diff options
author | Balajiganapathi S <balajiganapathi.s@gmail.com> | 2017-11-18 00:55:07 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-11-22 10:07:56 +0800 |
commit | d102deaec90f6f5bfe38140b459a05215d3254f9 (patch) | |
tree | a6f8f5df73bbe5454fe472d4d80042d5a071d8d3 /test | |
parent | c0b49694518d333a8ad62623321f839fc3b4bc6a (diff) | |
download | dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.gz dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.tar.zst dexon-solidity-d102deaec90f6f5bfe38140b459a05215d3254f9.zip |
Detect cyclic constant definitions
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index cedf7f3a..0d02ac34 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -7366,7 +7366,35 @@ BOOST_AUTO_TEST_CASE(array_length_cannot_be_constant_function_parameter) } } )"; - CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal."); + CHECK_ERROR(text, TypeError, "Constant identifier declaration must have a constant value."); +} + +BOOST_AUTO_TEST_CASE(array_length_with_cyclic_constant) +{ + char const* text = R"( + contract C { + uint constant LEN = LEN; + function f() { + uint[LEN] a; + } + } + )"; + CHECK_ERROR(text, TypeError, "Cyclic constant definition."); +} + +BOOST_AUTO_TEST_CASE(array_length_with_complex_cyclic_constant) +{ + char const* text = R"( + contract C { + uint constant L2 = LEN - 10; + uint constant L1 = L2 / 10; + uint constant LEN = 10 + L1 * 5; + function f() { + uint[LEN] a; + } + } + )"; + CHECK_ERROR(text, TypeError, "Cyclic constant definition."); } BOOST_AUTO_TEST_CASE(array_length_with_pure_functions) |