Fix #8450. Prevented internal compiler errors when assigning nested tuples.

This commit is contained in:
a3d4 2020-03-30 15:18:51 +02:00
parent 1897138916
commit c002cae691
5 changed files with 45 additions and 2 deletions

View File

@ -10,6 +10,7 @@ Compiler Features:
Bugfixes:
* Inline Assembly: Fix internal error when accessing invalid constant variables.
* Reference Resolver: Fix internal error when accessing invalid struct members.
* Type Checker: Fix internal errors when assigning nested tuples.
* Inheritance: Allow public state variables to override functions with dynamic memory types in their return values.
* JSON AST: Always add pointer suffix for memory reference types.

View File

@ -1317,11 +1317,11 @@ void TypeChecker::checkExpressionAssignment(Type const& _type, Expression const&
if (auto const* tupleExpression = dynamic_cast<TupleExpression const*>(&_expression))
{
auto const* tupleType = dynamic_cast<TupleType const*>(&_type);
auto const& types = tupleType ? tupleType->components() : vector<TypePointer> { &_type };
auto const& types = tupleType && tupleExpression->components().size() > 1 ? tupleType->components() : vector<TypePointer> { &_type };
solAssert(
tupleExpression->components().size() == types.size() || m_errorReporter.hasErrors(),
"Array sizes don't match or no errors generated."
"Array sizes don't match and no errors generated."
);
for (size_t i = 0; i < min(tupleExpression->components().size(), types.size()); i++)

View File

@ -0,0 +1,24 @@
contract test {
function f0() public returns(int, bool) {
int a;
bool b;
((a, b)) = (2, true);
return (a, b);
}
function f1() public returns(int) {
int a;
(((a, ), )) = ((1, 2) ,3);
return a;
}
function f2() public returns(int) {
int a;
(((, a),)) = ((1, 2), 3);
return a;
}
}
// ====
// compileViaYul: also
// ----
// f0() -> 2, true
// f1() -> 1
// f2() -> 2

View File

@ -0,0 +1,12 @@
contract C {
function f() {
(((((((((((,2),)),)),),))=4)));
}
}
// ----
// SyntaxError: (15-69): No visibility specified. Did you intend to add "public"?
// TypeError: (46-47): Expression has to be an lvalue.
// TypeError: (60-61): Type int_const 4 is not implicitly convertible to expected type tuple(tuple(tuple(tuple(tuple(,int_const 2),),),),).
// TypeError: (37-61): Tuple component cannot be empty.
// TypeError: (36-62): Tuple component cannot be empty.
// TypeError: (35-63): Tuple component cannot be empty.

View File

@ -0,0 +1,6 @@
contract C {
function f() public pure {
int a;
(((a,),)) = ((1,2),3);
}
}