From 276229cc58e00dabeb1c7d800e91131816969a02 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 6 Mar 2017 14:49:51 +0100 Subject: Tests for no compound assignment for tuples. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 3d82fc70..da3e81ed 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2992,6 +2992,18 @@ BOOST_AUTO_TEST_CASE(tuple_assignment_from_void_function) CHECK_ERROR(text, TypeError, "Cannot declare variable with void (empty tuple) type."); } +BOOST_AUTO_TEST_CASE(tuple_compound_assignment) +{ + char const* text = R"( + contract C { + function f() returns (uint a, uint b) { + (a, b) += (1, 1); + } + } + )"; + CHECK_ERROR(text, TypeError, "Compound assignment is not allowed for tuple types."); +} + BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity) { char const* text = R"( -- cgit v1.2.3 From 93ef7fd260d680cf6e984e286427542e24749bca Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 6 Mar 2017 14:50:00 +0100 Subject: Disallow compound assignment for tuples. --- libsolidity/analysis/TypeChecker.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 93b183a2..acceffda 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -947,6 +947,11 @@ bool TypeChecker::visit(Assignment const& _assignment) _assignment.annotation().type = t; if (TupleType const* tupleType = dynamic_cast(t.get())) { + if (_assignment.assignmentOperator() != Token::Assign) + typeError( + _assignment.location(), + "Compound assignment is not allowed for tuple types." + ); // Sequenced assignments of tuples is not valid, make the result a "void" type. _assignment.annotation().type = make_shared(); expectType(_assignment.rightHandSide(), *tupleType); -- cgit v1.2.3 From c7d61a2c6afb88787174bbb6a7bce934deefef70 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 6 Mar 2017 14:50:31 +0100 Subject: Changelog entry. --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 178bd39f..8900eab7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ Bugfixes: * Commandline interface: Do not try creating paths ``.`` and ``..``. * Parser: Disallow octal literals. * Type system: Fix a crash caused by continuing on fatal errors in the code. + * Type system: Disallow compound assignment for tuples. * Type system: Detect cyclic dependencies between constants. * Type system: Disallow arrays with negative length. * Type system: Fix a crash related to invalid binary operators. -- cgit v1.2.3