From b8fc58850d9f37c22dedca3ed189f2fdd5458236 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 26 Jul 2017 14:19:32 +0200 Subject: [PATCH 1/3] Test for assigning to non-lvalue. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 4b29243ac..de698c775 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -6382,6 +6382,20 @@ BOOST_AUTO_TEST_CASE(using_this_in_constructor) CHECK_WARNING(text, "\"this\" used in constructor"); } +BOOST_AUTO_TEST_CASE(do_not_crash_on_not_lalue) +{ + // This checks for a bug that caused a crash because of continued analysis. + char const* text = R"( + contract C { + mapping (uint => uint) m; + function f() { + m(1) = 2; + } + } + )"; + CHECK_ERROR_ALLOW_MULTI(text, TypeError, "is not callable"); +} + BOOST_AUTO_TEST_SUITE_END() } From cb75e6218b4e02cb7c7a592598211503d44abc12 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 26 Jul 2017 14:19:46 +0200 Subject: [PATCH 2/3] Fix crash on assignment to non-lvalue. --- libsolidity/analysis/TypeChecker.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 23f01752b..7a766489b 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1124,7 +1124,9 @@ bool TypeChecker::visit(Assignment const& _assignment) _assignment.annotation().type = make_shared(); expectType(_assignment.rightHandSide(), *tupleType); - checkDoubleStorageAssignment(_assignment); + // expectType does not cause fatal errors, so we have to check again here. + if (dynamic_cast(type(_assignment.rightHandSide()).get())) + checkDoubleStorageAssignment(_assignment); } else if (t->category() == Type::Category::Mapping) { From d78f94f0dd82af847dcac40636d1fe83cbff8e4f Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 27 Jul 2017 11:51:01 +0200 Subject: [PATCH 3/3] Changelog entry. --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 361864626..9d41a812d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ Features: * Type checker: Warn if using ``this`` in a constructor. Bugfixes: + * Type Checker: Fix crash for some assignment to non-lvalue. * Type Checker: Fix invalid "specify storage keyword" warning for reference members of structs. * Type Checker: Mark modifiers as internal.