diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-07-05 17:04:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-05 17:04:16 +0800 |
commit | 05a26fc98c1201057c618c536ca0537e456c9b15 (patch) | |
tree | 330e580a258f59ddebe926cf61c9fd68297a753c | |
parent | 2b505e7a6fb2f2a36582f2eed1e75bc20039175c (diff) | |
parent | 2432808793ea737a28f9c75042730724f4d050e8 (diff) | |
download | dexon-solidity-05a26fc98c1201057c618c536ca0537e456c9b15.tar dexon-solidity-05a26fc98c1201057c618c536ca0537e456c9b15.tar.gz dexon-solidity-05a26fc98c1201057c618c536ca0537e456c9b15.tar.bz2 dexon-solidity-05a26fc98c1201057c618c536ca0537e456c9b15.tar.lz dexon-solidity-05a26fc98c1201057c618c536ca0537e456c9b15.tar.xz dexon-solidity-05a26fc98c1201057c618c536ca0537e456c9b15.tar.zst dexon-solidity-05a26fc98c1201057c618c536ca0537e456c9b15.zip |
Merge pull request #2518 from ethereum/fixInternalVariableAlreadyPresent
Fix internal variable already present error.
-rw-r--r-- | Changelog.md | 3 | ||||
-rw-r--r-- | libsolidity/codegen/ContractCompiler.cpp | 3 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 27 |
3 files changed, 33 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md index 7c0c86a5..b4415978 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ ### 0.4.13 (unreleased) +Bugfixes: + * Code Generator: Correctly unregister modifier variables. + ### 0.4.12 (2017-07-03) Features: diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index c358a519..cad388df 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -928,7 +928,10 @@ void ContractCompiler::appendModifierOrFunctionCode() ); } for (VariableDeclaration const* localVariable: modifier.localVariables()) + { + addedVariables.push_back(localVariable); appendStackVariableInitialisation(*localVariable); + } stackSurplus = CompilerUtils::sizeOnStack(modifier.parameters()) + diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a6c01283..c9771fbd 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9696,6 +9696,33 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly) BOOST_CHECK(callContractFunction("i()") == fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); } +BOOST_AUTO_TEST_CASE(multi_modifiers) +{ + // This triggered a bug in some version because the variable in the modifier was not + // unregistered correctly. + char const* sourceCode = R"( + contract C { + uint public x; + modifier m1 { + address a1 = msg.sender; + x++; + _; + } + function f1() m1() { + x += 7; + } + function f2() m1() { + x += 3; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f1()") == bytes()); + BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(8))); + BOOST_CHECK(callContractFunction("f2()") == bytes()); + BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(12))); +} + BOOST_AUTO_TEST_SUITE_END() } |