mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Bugfix: Returning literal strings in tuples.
This commit is contained in:
parent
56f5d58850
commit
a5c227778d
@ -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))
|
||||
|
@ -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;
|
||||
|
@ -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"(
|
||||
|
Loading…
Reference in New Issue
Block a user