Merge pull request #185 from chriseth/fix_strings_in_tuples

Bugfix: Returning literal strings in tuples.
This commit is contained in:
chriseth 2015-11-02 17:11:02 +01:00
commit 5981ee4013
3 changed files with 26 additions and 2 deletions

View File

@ -606,7 +606,11 @@ bool Compiler::visit(Return const& _return)
for (auto const& retVariable: returnParameters)
types.push_back(retVariable->annotation().type);
TypePointer expectedType = types.size() == 1 ? types.front() : make_shared<TupleType>(types);
TypePointer expectedType;
if (expression->annotation().type->category() == Type::Category::Tuple || types.size() != 1)
expectedType = make_shared<TupleType>(types);
else
expectedType = types.front();
compileExpression(*expression, expectedType);
for (auto const& retVariable: boost::adaptors::reverse(returnParameters))

View File

@ -598,7 +598,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
}
// Value grew
if (targetSize > sourceSize)
moveIntoStack(depth + targetSize - sourceSize, targetSize - sourceSize);
moveIntoStack(depth + targetSize - sourceSize - 1, targetSize - sourceSize);
}
}
depth -= sourceSize;

View File

@ -5682,6 +5682,26 @@ BOOST_AUTO_TEST_CASE(tuples)
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0)));
}
BOOST_AUTO_TEST_CASE(string_tuples)
{
char const* sourceCode = R"(
contract C {
function f() returns (string, uint) {
return ("abc", 8);
}
function g() returns (string, string) {
return (h(), "def");
}
function h() returns (string) {
return ("abc",);
}
}
)";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(0x40), u256(8), u256(3), string("abc")));
BOOST_CHECK(callContractFunction("g()") == encodeArgs(u256(0x40), u256(0x80), u256(3), string("abc"), u256(3), string("def")));
}
BOOST_AUTO_TEST_CASE(destructuring_assignment)
{
char const* sourceCode = R"(