Skip to content

Commit c88b3cf

Browse files
committed
Fix segmentation fault when resolving to empty left hand side tuple-type
1 parent e202d30 commit c88b3cf

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Bugfixes:
1616
* SMTChecker: Fix internal error when using bitwise operators with an array element as argument.
1717
* Standard JSON Interface: Fix ICE when the optimizer is disabled and an empty/blank string is used for ``optimizerSteps`` sequence.
1818
* StaticAnalyzer: Only raise a compile time error for division and modulo by zero when it's between literals.
19+
* TypeChecker: Fix segmentation fault when assigning to complex left side tuple expression that resolves to empty.
1920
* Yul Optimizer: Fix the order of assignments generated by ``SSATransform`` being dependent on AST IDs, sometimes resulting in different (but equivalent) bytecode when unrelated files were added to the compilation pipeline.
2021

2122

libsolidity/analysis/TypeChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ void TypeChecker::checkDoubleStorageAssignment(Assignment const& _assignment)
116116
TupleType const& lhsType = dynamic_cast<TupleType const&>(*type(_lhs));
117117
TupleExpression const* lhsResolved = dynamic_cast<TupleExpression const*>(resolveOuterUnaryTuples(&_lhs));
118118

119-
if (lhsType.components().size() != _rhs.components().size() || lhsResolved->components().size() != _rhs.components().size())
119+
solAssert(!lhsResolved || lhsResolved->components().size() == lhsType.components().size());
120+
if (lhsType.components().size() != _rhs.components().size())
120121
{
121122
solAssert(m_errorReporter.hasErrors(), "");
122123
return;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
contract C {
2+
uint[] public array;
3+
4+
function f() public {
5+
(f()) = ();
6+
}
7+
8+
function g() public {
9+
(revert()) = ();
10+
}
11+
12+
function h() internal returns (uint, uint) {}
13+
14+
function i() public {
15+
(h()) = (1, 1);
16+
}
17+
18+
function j() public returns (uint, uint) {
19+
(j()) = (1, 1);
20+
}
21+
22+
function m() public {
23+
(uint x, uint y) = (1, 1); // OK
24+
}
25+
26+
function n() public {
27+
((array.push(), array.push())) = (1, 1); // OK
28+
}
29+
}
30+
// ----
31+
// TypeError 4247: (62-65): Expression has to be an lvalue.
32+
// TypeError 4247: (103-111): Expression has to be an lvalue.
33+
// TypeError 4247: (197-200): Expression has to be an lvalue.
34+
// TypeError 4247: (263-266): Expression has to be an lvalue.

0 commit comments

Comments
 (0)