aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-01-13 02:01:35 +0800
committerchriseth <c@ethdev.com>2016-01-13 02:01:35 +0800
commit02c1aacd25652d39678005294ecbb6180a283134 (patch)
treeddf0a97043f479851c86341c5157cedde12921e0 /libsolidity/analysis
parentcff368fb7c4d39b8610cec8c42b1652c42971e3e (diff)
parentc45593a44480f846302fdb652e23bd47988fba84 (diff)
downloaddexon-solidity-02c1aacd25652d39678005294ecbb6180a283134.tar.gz
dexon-solidity-02c1aacd25652d39678005294ecbb6180a283134.tar.zst
dexon-solidity-02c1aacd25652d39678005294ecbb6180a283134.zip
Merge pull request #345 from VoR0220/develop
Inline Arrays
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 669a7e4a..ab1151a1 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -783,10 +783,12 @@ 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;
+
if (_tuple.annotation().lValueRequested)
{
+ if (_tuple.isInlineArray())
+ fatalTypeError(_tuple.location(), "Inline array type cannot be declared as LValue.");
for (auto const& component: components)
if (component)
{
@@ -804,6 +806,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
}
else
{
+ TypePointer inlineArrayType;
for (size_t i = 0; i < components.size(); ++i)
{
// Outside of an lvalue-context, the only situation where a component can be empty is (x,).
@@ -813,18 +816,34 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
{
components[i]->accept(*this);
types.push_back(type(*components[i]));
+ if (_tuple.isInlineArray())
+ solAssert(!!types[i], "Inline array cannot have empty components");
+ if (i == 0 && _tuple.isInlineArray())
+ inlineArrayType = types[i]->mobileType();
+ else if (_tuple.isInlineArray() && inlineArrayType)
+ inlineArrayType = Type::commonType(inlineArrayType, types[i]->mobileType());
}
else
types.push_back(TypePointer());
}
- if (components.size() == 1)
- _tuple.annotation().type = type(*components[0]);
+ if (_tuple.isInlineArray())
+ {
+ if (!inlineArrayType)
+ fatalTypeError(_tuple.location(), "Unable to deduce common type for array elements.");
+ _tuple.annotation().type = make_shared<ArrayType>(DataLocation::Memory, inlineArrayType, types.size());
+ }
else
{
- if (components.size() == 2 && !components[1])
- types.pop_back();
- _tuple.annotation().type = make_shared<TupleType>(types);
+ if (components.size() == 1)
+ _tuple.annotation().type = type(*components[0]);
+ else
+ {
+ if (components.size() == 2 && !components[1])
+ types.pop_back();
+ _tuple.annotation().type = make_shared<TupleType>(types);
+ }
}
+
}
return false;
}