diff --git a/Changelog.md b/Changelog.md index 8468321e9..18066a775 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ Compiler Features: Bugfixes: + * Type Checker: Fix internal compiler error on tuple assignments with invalid left-hand side. ### 0.8.16 (2022-08-08) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 5b64bcea8..de3cdc847 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -166,8 +166,15 @@ void TypeChecker::checkDoubleStorageAssignment(Assignment const& _assignment) ); } }; + + TupleExpression const* lhsTupleExpression = dynamic_cast(&_assignment.leftHandSide()); + if (!lhsTupleExpression) + { + solAssert(m_errorReporter.hasErrors()); + return; + } count( - dynamic_cast(_assignment.leftHandSide()), + *lhsTupleExpression, dynamic_cast(*type(_assignment.rightHandSide())), count ); diff --git a/test/libsolidity/syntaxTests/tupleAssignments/tuple_to_function_assignment.sol b/test/libsolidity/syntaxTests/tupleAssignments/tuple_to_function_assignment.sol new file mode 100644 index 000000000..898c79101 --- /dev/null +++ b/test/libsolidity/syntaxTests/tupleAssignments/tuple_to_function_assignment.sol @@ -0,0 +1,17 @@ +contract C { + function f() internal pure {} + function g() internal pure returns (uint256) {} + function h() internal pure returns (uint256, uint256) {} + function test() public pure { + f() = (); + g() = (uint256(1)); + h() = (uint256(1), uint256(2)); + h() = (); + } +} +// ---- +// TypeError 4247: (184-187): Expression has to be an lvalue. +// TypeError 4247: (196-199): Expression has to be an lvalue. +// TypeError 4247: (218-221): Expression has to be an lvalue. +// TypeError 4247: (252-255): Expression has to be an lvalue. +// TypeError 7407: (258-260): Type tuple() is not implicitly convertible to expected type tuple(uint256,uint256).