From 33590d513e278526bdfbf4bd18ea5236a8911bb0 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Wed, 26 Oct 2016 15:17:26 +0200 Subject: [PATCH 1/3] test: add a test for #621 --- test/libsolidity/SolidityEndToEndTest.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a1430b02c..bab54fab5 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -6353,6 +6353,20 @@ BOOST_AUTO_TEST_CASE(decayed_tuple) BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(2))); } +BOOST_AUTO_TEST_CASE(inline_tuple_with_rational_numbers) +{ + char const* sourceCode = R"( + contract c { + function f() returns (int8) { + int8[5] memory foo3 = [int8(1), -1, 0, 0, 0]; + return foo3[0]; + } + } + )"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1))); +} + BOOST_AUTO_TEST_CASE(destructuring_assignment) { char const* sourceCode = R"( From 6c15757618924a0da4491a243740c7bf0f70f60f Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Wed, 26 Oct 2016 15:57:42 +0200 Subject: [PATCH 2/3] Type checker: move the burden of computing mobile type to commonType This solves #621 --- libsolidity/analysis/TypeChecker.cpp | 4 ++-- libsolidity/ast/Types.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 46f4f7f6d..f934b2c8d 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -996,9 +996,9 @@ bool TypeChecker::visit(TupleExpression const& _tuple) fatalTypeError(components[i]->location(), "Invalid mobile type."); if (i == 0) - inlineArrayType = types[i]->mobileType(); + inlineArrayType = types[i]; else if (inlineArrayType) - inlineArrayType = Type::commonType(inlineArrayType, types[i]->mobileType()); + inlineArrayType = Type::commonType(inlineArrayType, types[i]); } } else diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 7fe97fa76..0e077b32c 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -200,10 +200,10 @@ TypePointer Type::commonType(TypePointer const& _a, TypePointer const& _b) { if (!_a || !_b) return TypePointer(); - else if (_b->isImplicitlyConvertibleTo(*_a)) - return _a; - else if (_a->isImplicitlyConvertibleTo(*_b)) - return _b; + else if (_b->isImplicitlyConvertibleTo(*_a->mobileType())) + return _a->mobileType(); + else if (_a->isImplicitlyConvertibleTo(*_b->mobileType())) + return _b->mobileType(); else return TypePointer(); } From 41170d55075fc056a688dc8fb29021e23b645cc0 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Wed, 9 Nov 2016 11:58:48 +0100 Subject: [PATCH 3/3] Changelog: add a point about #1293 --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 1ae2f57ee..d76303ab4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,7 @@ Features: * Do-while loops: support for a C-style do{}while(); control structure + * Type checker: now more eagerly searches for a common type of an inline array with mixed types ### 0.4.4 (2016-10-31)