diff options
author | Christian Parpart <christian@parpart.family> | 2018-10-05 21:38:14 +0800 |
---|---|---|
committer | Christian Parpart <christian@ethereum.org> | 2018-10-15 16:35:11 +0800 |
commit | 6d815a142fbf85e19ab4f061c6e4275a26ff2e5f (patch) | |
tree | e8ccd335af9f64d139304d23bb3dc8df50577cfa | |
parent | 26dc876c28718613ad64961e65374ace1139010b (diff) | |
download | dexon-solidity-6d815a142fbf85e19ab4f061c6e4275a26ff2e5f.tar dexon-solidity-6d815a142fbf85e19ab4f061c6e4275a26ff2e5f.tar.gz dexon-solidity-6d815a142fbf85e19ab4f061c6e4275a26ff2e5f.tar.bz2 dexon-solidity-6d815a142fbf85e19ab4f061c6e4275a26ff2e5f.tar.lz dexon-solidity-6d815a142fbf85e19ab4f061c6e4275a26ff2e5f.tar.xz dexon-solidity-6d815a142fbf85e19ab4f061c6e4275a26ff2e5f.tar.zst dexon-solidity-6d815a142fbf85e19ab4f061c6e4275a26ff2e5f.zip |
Fixes invalid function calls to literals inside tuple assignment's LHS.
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 8 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/types/function_call_fail.sol | 9 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/types/function_call_fail2.sol | 7 |
3 files changed, 22 insertions, 2 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 069be156..164b0b02 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1444,8 +1444,12 @@ void TypeChecker::checkExpressionAssignment(Type const& _type, Expression const& auto const* tupleType = dynamic_cast<TupleType const*>(&_type); auto const& types = tupleType ? tupleType->components() : vector<TypePointer> { _type.shared_from_this() }; - solAssert(tupleExpression->components().size() == types.size(), ""); - for (size_t i = 0; i < types.size(); i++) + solAssert( + tupleExpression->components().size() == types.size() || m_errorReporter.hasErrors(), + "Array sizes don't match or no errors generated." + ); + + for (size_t i = 0; i < min(tupleExpression->components().size(), types.size()); i++) if (types[i]) { solAssert(!!tupleExpression->components()[i], ""); diff --git a/test/libsolidity/syntaxTests/types/function_call_fail.sol b/test/libsolidity/syntaxTests/types/function_call_fail.sol new file mode 100644 index 00000000..ef52ab44 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/function_call_fail.sol @@ -0,0 +1,9 @@ +contract C { + function f(uint y) public pure { + (4(y)) = 2; + } +} +// ---- +// TypeError: (59-63): Type is not callable +// TypeError: (59-63): Expression has to be an lvalue. +// TypeError: (67-68): Type int_const 2 is not implicitly convertible to expected type tuple(). diff --git a/test/libsolidity/syntaxTests/types/function_call_fail2.sol b/test/libsolidity/syntaxTests/types/function_call_fail2.sol new file mode 100644 index 00000000..389ffce9 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/function_call_fail2.sol @@ -0,0 +1,7 @@ +contract C { + function f(uint y) public pure returns (uint) { + (f(y)) = 2; + } +} +// ---- +// TypeError: (74-78): Expression has to be an lvalue. |