diff options
-rw-r--r-- | Changelog.md | 2 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 3 | ||||
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 6 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 20 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/inline_arrays/inline_array_of_mapping_type.sol | 8 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/memberLookup/internal_function_type.sol | 7 |
6 files changed, 43 insertions, 3 deletions
diff --git a/Changelog.md b/Changelog.md index 99c1ead8..1c3fcde4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -18,11 +18,13 @@ Bugfixes: * Assembly output: Do not mix in/out jump annotations with arguments. * Commandline interface: Fix crash when using ``--ast`` on empty runtime code. * Code Generator: Annotate jump from calldata decoder to function as "jump in". + * Code Generator: Fix internal error related to state variables of function type access via base contract name. * Optimizer: Fix nondeterminism bug related to the boost version and constants representation. The bug only resulted in less optimal but still correct code because the generated routine is always verified to be correct. * Type Checker: Properly detect different return types when overriding an external interface function with a public contract function. * Type Checker: Disallow struct return types for getters of public state variables unless the new ABI encoder is active. * Type Checker: Fix internal compiler error when a field of a struct used as a parameter in a function type has a non-existent type. * Type Checker: Disallow functions ``sha3`` and ``suicide`` also without a function call. + * Type Checker: Disallow inline arrays of mapping type. Build System: * Emscripten: Upgrade to Emscripten SDK 1.37.21 and boost 1.67. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 16b6a55e..a80ca7d6 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1608,6 +1608,9 @@ bool TypeChecker::visit(TupleExpression const& _tuple) { if (!inlineArrayType) m_errorReporter.fatalTypeError(_tuple.location(), "Unable to deduce common type for array elements."); + else if (!inlineArrayType->canLiveOutsideStorage()) + m_errorReporter.fatalTypeError(_tuple.location(), "Type " + inlineArrayType->toString() + " is only valid in storage."); + _tuple.annotation().type = make_shared<ArrayType>(DataLocation::Memory, inlineArrayType, types.size()); } else diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 87eecd2e..121585d9 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1153,7 +1153,9 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) if (dynamic_cast<ContractType const*>(type->actualType().get())) { solAssert(_memberAccess.annotation().type, "_memberAccess has no type"); - if (auto funType = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type.get())) + if (auto variable = dynamic_cast<VariableDeclaration const*>(_memberAccess.annotation().referencedDeclaration)) + appendVariable(*variable, static_cast<Expression const&>(_memberAccess)); + else if (auto funType = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type.get())) { switch (funType->kind()) { @@ -1199,8 +1201,6 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) { // no-op } - else if (auto variable = dynamic_cast<VariableDeclaration const*>(_memberAccess.annotation().referencedDeclaration)) - appendVariable(*variable, static_cast<Expression const&>(_memberAccess)); else _memberAccess.expression().accept(*this); } diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 05bb7446..c6135a72 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -14213,6 +14213,26 @@ BOOST_AUTO_TEST_CASE(external_public_override) ABI_CHECK(callContractFunction("f()"), encodeArgs(2)); ABI_CHECK(callContractFunction("g()"), encodeArgs(2)); } + +BOOST_AUTO_TEST_CASE(base_access_to_function_type_variables) +{ + char const* sourceCode = R"( + contract C { + function () internal returns (uint) x; + function set() public { + C.x = g; + } + function g() public pure returns (uint) { return 2; } + function h() public returns (uint) { return C.x(); } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("g()"), encodeArgs(2)); + ABI_CHECK(callContractFunction("h()"), encodeArgs()); + ABI_CHECK(callContractFunction("set()"), encodeArgs()); + ABI_CHECK(callContractFunction("h()"), encodeArgs(2)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/syntaxTests/inline_arrays/inline_array_of_mapping_type.sol b/test/libsolidity/syntaxTests/inline_arrays/inline_array_of_mapping_type.sol new file mode 100644 index 00000000..59a88130 --- /dev/null +++ b/test/libsolidity/syntaxTests/inline_arrays/inline_array_of_mapping_type.sol @@ -0,0 +1,8 @@ +contract C { + mapping(int => int) a; + function f() public { + [a]; + } +} +// ---- +// TypeError: (66-69): Type mapping(int256 => int256) is only valid in storage. diff --git a/test/libsolidity/syntaxTests/memberLookup/internal_function_type.sol b/test/libsolidity/syntaxTests/memberLookup/internal_function_type.sol new file mode 100644 index 00000000..560a6c2a --- /dev/null +++ b/test/libsolidity/syntaxTests/memberLookup/internal_function_type.sol @@ -0,0 +1,7 @@ +contract C { + function () internal returns (uint) x; + constructor() public { + C.x = g; + } + function g() public pure returns (uint) {} +} |