diff options
author | RJ <catalanor0220@gmail.com> | 2016-01-10 15:09:58 +0800 |
---|---|---|
committer | RJ <catalanor0220@gmail.com> | 2016-01-10 15:09:58 +0800 |
commit | df9dfa8feff8637d786342ca2c33286b72dd2d10 (patch) | |
tree | fdea4ef9f515aafb143c24a7ca4f94af59efd2d8 | |
parent | 10a1c352b9c274ba24b9915dfe2d6088616a69c2 (diff) | |
download | dexon-solidity-df9dfa8feff8637d786342ca2c33286b72dd2d10.tar.gz dexon-solidity-df9dfa8feff8637d786342ca2c33286b72dd2d10.tar.zst dexon-solidity-df9dfa8feff8637d786342ca2c33286b72dd2d10.zip |
find common type
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index de30dcf7..20b3ad6c 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -780,8 +780,9 @@ bool TypeChecker::visit(Assignment const& _assignment) bool TypeChecker::visit(TupleExpression const& _tuple) { vector<ASTPointer<Expression>> const& components = _tuple.components(); - solAssert(!_tuple.isInlineArray(), "Tuple type not properly declared"); TypePointers types; + TypePointer internalArrayType; + bool isArray = _tuple.isInlineArray(); if (_tuple.annotation().lValueRequested) { for (auto const& component: components) @@ -810,12 +811,20 @@ bool TypeChecker::visit(TupleExpression const& _tuple) { components[i]->accept(*this); types.push_back(type(*components[i])); + if (i == 0 && isArray) + internalArrayType = types[i]->mobileType(); + else if (isArray && internalArrayType && types[i]->mobileType()) + internalArrayType = Type::commonType(internalArrayType, types[i]->mobileType()); } else types.push_back(TypePointer()); } - if (components.size() == 1) + if (components.size() == 1 && !isArray) _tuple.annotation().type = type(*components[0]); + else if (!internalArrayType && isArray) + fatalTypeError(_tuple.location(), "Unable to deduce common type for array elements."); + else if (isArray) + _tuple.annotation().type = make_shared<ArrayType>(DataLocation::Memory, internalArrayType, types.size()); else { if (components.size() == 2 && !components[1]) |