diff options
author | chriseth <chris@ethereum.org> | 2017-04-25 01:25:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-25 01:25:45 +0800 |
commit | 4d111e3366c9ddf15a750569baeed3fccb201682 (patch) | |
tree | 1f03eaffe028016a920d3ef9f699edf1ab177d8f /test | |
parent | 0b2a05c84d83b1f22acb4201d0792d7f7865d1f9 (diff) | |
parent | 9577f87dfcd2d8b532f698c0aa1e8f9c01bb0ba5 (diff) | |
download | dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.tar dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.tar.gz dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.tar.bz2 dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.tar.lz dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.tar.xz dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.tar.zst dexon-solidity-4d111e3366c9ddf15a750569baeed3fccb201682.zip |
Merge pull request #2152 from ethereum/warnRevert
Warn about side-effect free statements.
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 79 |
1 files changed, 64 insertions, 15 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 1388f01b..b98c3706 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -3653,54 +3653,56 @@ BOOST_AUTO_TEST_CASE(conditional_with_all_types) // integers uint x; uint y; - true ? x : y; + uint g = true ? x : y; // integer constants - true ? 1 : 3; + uint h = true ? 1 : 3; // string literal - true ? "hello" : "world"; - + var i = true ? "hello" : "world"; + } + function f2() { // bool - true ? true : false; + bool j = true ? true : false; // real is not there yet. // array byte[2] memory a; byte[2] memory b; - true ? a : b; + var k = true ? a : b; bytes memory e; bytes memory f; - true ? e : f; + var l = true ? e : f; // fixed bytes bytes2 c; bytes2 d; - true ? c : d; - + var m = true ? c : d; + } + function f3() { // contract doesn't fit in here // struct - true ? struct_x : struct_y; + struct_x = true ? struct_x : struct_y; // function - true ? fun_x : fun_y; + var r = true ? fun_x : fun_y; // enum small enum_x; small enum_y; - true ? enum_x : enum_y; + enum_x = true ? enum_x : enum_y; // tuple - true ? (1, 2) : (3, 4); + var (n, o) = true ? (1, 2) : (3, 4); // mapping - true ? table1 : table2; + var p = true ? table1 : table2; // typetype - true ? uint32(1) : uint32(2); + var q = true ? uint32(1) : uint32(2); // modifier doesn't fit in here @@ -5477,6 +5479,53 @@ BOOST_AUTO_TEST_CASE(using_interface_complex) success(text); } +BOOST_AUTO_TEST_CASE(bare_revert) +{ + char const* text = R"( + contract C { + function f(uint x) { + if (x > 7) + revert; + } + } + )"; + CHECK_WARNING(text, "Statement has no effect."); +} + +BOOST_AUTO_TEST_CASE(bare_others) +{ + CHECK_WARNING("contract C { function f() { selfdestruct; } }", "Statement has no effect."); + CHECK_WARNING("contract C { function f() { assert; } }", "Statement has no effect."); + CHECK_WARNING("contract C { function f() { require; } }", "Statement has no effect."); + CHECK_WARNING("contract C { function f() { suicide; } }", "Statement has no effect."); +} + +BOOST_AUTO_TEST_CASE(pure_statement_in_for_loop) +{ + char const* text = R"( + contract C { + function f() { + for (uint x = 0; x < 10; true) + x++; + } + } + )"; + CHECK_WARNING(text, "Statement has no effect."); +} + +BOOST_AUTO_TEST_CASE(pure_statement_check_for_regular_for_loop) +{ + char const* text = R"( + contract C { + function f() { + for (uint x = 0; true; x++) + {} + } + } + )"; + success(text); +} + BOOST_AUTO_TEST_SUITE_END() } |