diff options
author | chriseth <c@ethdev.com> | 2017-03-02 02:12:40 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2017-03-13 20:30:21 +0800 |
commit | f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa (patch) | |
tree | 0dc1b367e2f5bc285457dc4358b2377ad4d5d1f0 /test | |
parent | bde913f088c873cba75db30b2d463f50f9dfe862 (diff) | |
download | dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.tar.gz dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.tar.zst dexon-solidity-f39763e91c97b29bfe6d2c79cb1c1ebf80b2b9aa.zip |
Type checking for pure expressions.
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index aef93e92..90831ccd 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2180,7 +2180,18 @@ BOOST_AUTO_TEST_CASE(assigning_state_to_const_variable) address constant x = msg.sender; } )"; - CHECK_ERROR(text, TypeError, "Expression is not compile-time constant."); + CHECK_ERROR(text, TypeError, "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"( + 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) @@ -2197,7 +2208,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_expression) { char const* text = R"( contract C { - uint constant x = 0x123 + 9x456; + uint constant x = 0x123 + 0x456; } )"; CHECK_SUCCESS(text); @@ -2207,7 +2218,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_keccak) { char const* text = R"( contract C { - bytes32 constant x = keccak("abc"); + bytes32 constant x = keccak256("abc"); } )"; CHECK_SUCCESS(text); @@ -2217,22 +2228,21 @@ BOOST_AUTO_TEST_CASE(assignment_to_const_array_vars) { char const* text = R"( contract C { - uint[3] memory constant x = [1, 2, 3]; + uint[3] constant x = [uint(1), 2, 3]; } )"; CHECK_SUCCESS(text); } -BOOST_AUTO_TEST_CASE(complex_const_variable) +BOOST_AUTO_TEST_CASE(constant_struct) { - //for now constant specifier is valid only for uint bytesXX and enums char const* text = R"( - contract Foo { - mapping(uint => bool) x; - mapping(uint => bool) constant mapVar = x; + contract C { + struct S { uint x; uint[] y; } + S constant x = S(5, new uint[](4)); } )"; - CHECK_ERROR(text, TypeError, ""); + CHECK_SUCCESS(text); } BOOST_AUTO_TEST_CASE(uninitialized_const_variable) |