aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/frequently-asked-questions.rst10
-rw-r--r--libsolidity/ast/Types.cpp29
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp16
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp15
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp26
5 files changed, 82 insertions, 14 deletions
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index fd68aa11..cf037131 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -554,6 +554,16 @@ What is the difference between `bytes` and `byte[]`?
CALLDATA) or in memory, every single element of a `byte[]` is padded to 32
bytes which wastes 31 bytes per element.
+Is it possible to send a value while calling an overloaded function?
+====================================================================
+
+It's a known missing feature. https://www.pivotaltracker.com/story/show/92020468
+as part of https://www.pivotaltracker.com/n/projects/1189488
+
+Best solution currently see is to introduce a special case for gas and value and
+just re-check whether they are present at the point of overload resolution.
+
+
******************
Advanced Questions
******************
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 49347022..2e9b56a1 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -831,6 +831,8 @@ bool ArrayType::operator==(Type const& _other) const
other.isDynamicallySized() != isDynamicallySized()
)
return false;
+ if (*other.baseType() != *baseType())
+ return false;
return isDynamicallySized() || length() == other.length();
}
@@ -1042,12 +1044,14 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con
}
}
else
+ {
for (auto const& it: m_contract.interfaceFunctions())
members.push_back(MemberList::Member(
it.second->declaration().name(),
it.second->asMemberFunction(m_contract.isLibrary()),
&it.second->declaration()
));
+ }
return members;
}
@@ -1858,6 +1862,12 @@ MemberList::MemberMap TypeType::nativeMembers(ContractDefinition const* _current
if (m_actualType->category() == Category::Contract)
{
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*m_actualType).contractDefinition();
+ bool isBase = false;
+ if (_currentScope != nullptr)
+ {
+ auto const& currentBases = _currentScope->annotation().linearizedBaseContracts;
+ isBase = (find(currentBases.begin(), currentBases.end(), &contract) != currentBases.end());
+ }
if (contract.isLibrary())
for (auto const& it: contract.interfaceFunctions())
members.push_back(MemberList::Member(
@@ -1865,14 +1875,19 @@ MemberList::MemberMap TypeType::nativeMembers(ContractDefinition const* _current
it.second->asMemberFunction(true), // use callcode
&it.second->declaration()
));
- else if (_currentScope != nullptr)
+ if (isBase)
{
- auto const& currentBases = _currentScope->annotation().linearizedBaseContracts;
- if (find(currentBases.begin(), currentBases.end(), &contract) != currentBases.end())
- // We are accessing the type of a base contract, so add all public and protected
- // members. Note that this does not add inherited functions on purpose.
- for (Declaration const* decl: contract.inheritableMembers())
- members.push_back(MemberList::Member(decl->name(), decl->type(), decl));
+ // We are accessing the type of a base contract, so add all public and protected
+ // members. Note that this does not add inherited functions on purpose.
+ for (Declaration const* decl: contract.inheritableMembers())
+ members.push_back(MemberList::Member(decl->name(), decl->type(), decl));
+ }
+ else
+ {
+ for (auto const& stru: contract.definedStructs())
+ members.push_back(MemberList::Member(stru->name(), stru->type(), stru));
+ for (auto const& enu: contract.definedEnums())
+ members.push_back(MemberList::Member(enu->name(), enu->type(), enu));
}
}
else if (m_actualType->category() == Category::Enum)
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index dcdab2a7..2fd0b2c4 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -913,14 +913,16 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
if (dynamic_cast<ContractType const*>(type.actualType().get()))
{
- auto const& funType = dynamic_cast<FunctionType const&>(*_memberAccess.annotation().type);
- if (funType.location() != FunctionType::Location::Internal)
- m_context << funType.externalIdentifier();
- else
+ if (auto funType = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type.get()))
{
- auto const* function = dynamic_cast<FunctionDefinition const*>(_memberAccess.annotation().referencedDeclaration);
- solAssert(!!function, "Function not found in member access");
- m_context << m_context.functionEntryLabel(*function).pushTag();
+ if (funType->location() != FunctionType::Location::Internal)
+ m_context << funType->externalIdentifier();
+ else
+ {
+ auto const* function = dynamic_cast<FunctionDefinition const*>(_memberAccess.annotation().referencedDeclaration);
+ solAssert(!!function, "Function not found in member access");
+ m_context << m_context.functionEntryLabel(*function).pushTag();
+ }
}
}
else if (auto enumType = dynamic_cast<EnumType const*>(type.actualType().get()))
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index f625f533..d57360dc 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -5377,6 +5377,21 @@ BOOST_AUTO_TEST_CASE(library_stray_values)
BOOST_CHECK(callContractFunction("f(uint256)", u256(33)) == encodeArgs(u256(42)));
}
+BOOST_AUTO_TEST_CASE(cross_contract_types)
+{
+ char const* sourceCode = R"(
+ contract Lib { struct S {uint a; uint b; } }
+ contract Test {
+ function f() returns (uint r) {
+ var x = Lib.S({a: 2, b: 3});
+ r = x.b;
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Test");
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(3)));
+}
+
BOOST_AUTO_TEST_CASE(simple_throw)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 1242e801..70c9eb0d 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -1348,6 +1348,21 @@ BOOST_AUTO_TEST_CASE(enum_member_access)
BOOST_CHECK(success(text));
}
+BOOST_AUTO_TEST_CASE(enum_member_access_accross_contracts)
+{
+ char const* text = R"(
+ contract Interface {
+ enum MyEnum { One, Two }
+ }
+ contract Impl {
+ function test() returns (Interface.MyEnum) {
+ return Interface.MyEnum.One;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
BOOST_AUTO_TEST_CASE(enum_invalid_member_access)
{
char const* text = R"(
@@ -2743,6 +2758,17 @@ BOOST_AUTO_TEST_CASE(invalid_args_creating_memory_array)
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(function_overload_array_type)
+{
+ char const* text = R"(
+ contract M {
+ function f(uint[] values);
+ function f(int[] values);
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
/*BOOST_AUTO_TEST_CASE(inline_array_declaration_and_passing)
{
char const* text = R"(