diff options
author | Federico Bond <federicobond@gmail.com> | 2017-07-09 07:27:28 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-10-03 22:30:16 +0800 |
commit | 2b8235269221cacbcf9beb793d969c451b1927a3 (patch) | |
tree | 7966106164c51f392f497057028160d6193e6409 /test | |
parent | 5c284589202c261c06dadfe7a598cc23752e8e48 (diff) | |
download | dexon-solidity-2b8235269221cacbcf9beb793d969c451b1927a3.tar dexon-solidity-2b8235269221cacbcf9beb793d969c451b1927a3.tar.gz dexon-solidity-2b8235269221cacbcf9beb793d969c451b1927a3.tar.bz2 dexon-solidity-2b8235269221cacbcf9beb793d969c451b1927a3.tar.lz dexon-solidity-2b8235269221cacbcf9beb793d969c451b1927a3.tar.xz dexon-solidity-2b8235269221cacbcf9beb793d969c451b1927a3.tar.zst dexon-solidity-2b8235269221cacbcf9beb793d969c451b1927a3.zip |
Disallow non-pure constant state variables in 0.5.0
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 8b112257..c60ccaf8 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2361,17 +2361,28 @@ BOOST_AUTO_TEST_CASE(assigning_value_to_const_variable) CHECK_ERROR(text, TypeError, "Cannot assign to a constant variable."); } -BOOST_AUTO_TEST_CASE(assigning_state_to_const_variable) +BOOST_AUTO_TEST_CASE(assigning_state_to_const_variable_0_4_x) { char const* text = R"( contract C { address constant x = msg.sender; } )"; - // Change to TypeError for 0.5.0. CHECK_WARNING(text, "Initial value for constant variable has to be compile-time constant."); } +BOOST_AUTO_TEST_CASE(assigning_state_to_const_variable) +{ + char const* text = R"( + pragma experimental "v0.5.0"; + + contract C { + address constant x = msg.sender; + } + )"; + CHECK_ERROR(text, TypeError, "Initial value for constant variable has to be compile-time constant."); +} + BOOST_AUTO_TEST_CASE(constant_string_literal_disallows_assignment) { char const* text = R"( @@ -2388,7 +2399,7 @@ BOOST_AUTO_TEST_CASE(constant_string_literal_disallows_assignment) CHECK_ERROR(text, TypeError, "Index access for string is not possible."); } -BOOST_AUTO_TEST_CASE(assign_constant_function_value_to_constant) +BOOST_AUTO_TEST_CASE(assign_constant_function_value_to_constant_0_4_x) { char const* text = R"( contract C { @@ -2396,10 +2407,22 @@ BOOST_AUTO_TEST_CASE(assign_constant_function_value_to_constant) uint constant y = x(); } )"; - // Change to TypeError for 0.5.0. CHECK_WARNING(text, "Initial value for constant variable has to be compile-time constant."); } +BOOST_AUTO_TEST_CASE(assign_constant_function_value_to_constant) +{ + char const* text = R"( + pragma experimental "v0.5.0"; + + contract C { + function () constant returns (uint) x; + uint constant y = x(); + } + )"; + CHECK_ERROR(text, TypeError, "Initial value for constant variable has to be compile-time constant."); +} + BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_conversion) { char const* text = R"( |