diff options
author | chriseth <c@ethdev.com> | 2015-11-01 06:13:45 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-11-01 06:13:45 +0800 |
commit | a5c227778d7f0145434147830bd07a16f0f72134 (patch) | |
tree | e92ab4d3ccd6bfbd7c0b89a9ffde4eb8d88f2251 | |
parent | 56f5d5885090a03ea9223f2210e70b6c78a1cb75 (diff) | |
download | dexon-solidity-a5c227778d7f0145434147830bd07a16f0f72134.tar dexon-solidity-a5c227778d7f0145434147830bd07a16f0f72134.tar.gz dexon-solidity-a5c227778d7f0145434147830bd07a16f0f72134.tar.bz2 dexon-solidity-a5c227778d7f0145434147830bd07a16f0f72134.tar.lz dexon-solidity-a5c227778d7f0145434147830bd07a16f0f72134.tar.xz dexon-solidity-a5c227778d7f0145434147830bd07a16f0f72134.tar.zst dexon-solidity-a5c227778d7f0145434147830bd07a16f0f72134.zip |
Bugfix: Returning literal strings in tuples.
-rw-r--r-- | libsolidity/codegen/Compiler.cpp | 6 | ||||
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 20 |
3 files changed, 26 insertions, 2 deletions
diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp index 457b1e02..5daa37de 100644 --- a/libsolidity/codegen/Compiler.cpp +++ b/libsolidity/codegen/Compiler.cpp @@ -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)) diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index cd84f5fc..dd38ef97 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -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; diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index fb7c4013..460396a8 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -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"( |