diff options
author | chriseth <chris@ethereum.org> | 2018-02-28 00:06:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-28 00:06:10 +0800 |
commit | 908b46e9a7f56a06c76db9e702fb9b25d8b0d344 (patch) | |
tree | 47594aa2e1c58a14557263f04199f01421622106 /test/libsolidity/SolidityEndToEndTest.cpp | |
parent | 6d8dee586c592b3ed34143b0e4c6cba3b704fa84 (diff) | |
parent | d64aa0eaad50741896020d31c0c93b64c3f03bc1 (diff) | |
download | dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.tar dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.tar.gz dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.tar.bz2 dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.tar.lz dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.tar.xz dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.tar.zst dexon-solidity-908b46e9a7f56a06c76db9e702fb9b25d8b0d344.zip |
Merge pull request #3476 from ethereum/scoping
C99/C++ scoping rules
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 3882e4ea..c352a2c2 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -284,6 +284,54 @@ BOOST_AUTO_TEST_CASE(conditional_expression_functions) ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(u256(2))); } +BOOST_AUTO_TEST_CASE(C99_scoping_activation) +{ + char const* sourceCode = R"( + pragma experimental "v0.5.0"; + contract test { + function f() pure public returns (uint) { + uint x = 7; + { + x = 3; // This should still assign to the outer variable + uint x; + x = 4; // This should assign to the new one + } + return x; + } + function g() pure public returns (uint x) { + x = 7; + { + x = 3; + uint x; + return x; // This returns the new variable, i.e. 0 + } + } + function h() pure public returns (uint x, uint a, uint b) { + x = 7; + { + x = 3; + a = x; // This should read from the outer + uint x = 4; + b = x; + } + } + function i() pure public returns (uint x, uint a) { + x = 7; + { + x = 3; + uint x = x; // This should read from the outer and assign to the inner + a = x; + } + } + } + )"; + compileAndRun(sourceCode); + ABI_CHECK(callContractFunction("f()"), encodeArgs(3)); + ABI_CHECK(callContractFunction("g()"), encodeArgs(0)); + ABI_CHECK(callContractFunction("h()"), encodeArgs(3, 3, 4)); + ABI_CHECK(callContractFunction("i()"), encodeArgs(3, 3)); +} + BOOST_AUTO_TEST_CASE(recursive_calls) { char const* sourceCode = R"( |