Merge pull request #1748 from ethereum/singletonArray

Use mobile type for singleton array.
This commit is contained in:
chriseth 2017-03-08 16:11:03 +01:00 committed by GitHub
commit 3f9a775834
2 changed files with 15 additions and 1 deletions

View File

@ -1029,7 +1029,7 @@ bool TypeChecker::visit(TupleExpression const& _tuple)
fatalTypeError(components[i]->location(), "Invalid mobile type.");
if (i == 0)
inlineArrayType = types[i];
inlineArrayType = types[i]->mobileType();
else if (inlineArrayType)
inlineArrayType = Type::commonType(inlineArrayType, types[i]);
}

View File

@ -7260,6 +7260,20 @@ BOOST_AUTO_TEST_CASE(inline_array_return)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(1, 2, 3, 4, 5));
}
BOOST_AUTO_TEST_CASE(inline_array_singleton)
{
// This caused a failure since the type was not converted to its mobile type.
char const* sourceCode = R"(
contract C {
function f() returns (uint) {
return [4][0];
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(4)));
}
BOOST_AUTO_TEST_CASE(inline_long_string_return)
{
char const* sourceCode = R"(