diff options
author | chriseth <chris@ethereum.org> | 2018-05-02 21:56:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-02 21:56:06 +0800 |
commit | 42289b642ff12d9275dedf10c257cfec8295feed (patch) | |
tree | 387ecf7c3325763bc46485ef183f0df3f608b1d8 /test/libsolidity | |
parent | 451e8edb1a095a8958eba96a0435ff9fb9ffb2a9 (diff) | |
parent | d43436cfec7cb1820f8f588a8a877e1cbf48b919 (diff) | |
download | dexon-solidity-42289b642ff12d9275dedf10c257cfec8295feed.tar dexon-solidity-42289b642ff12d9275dedf10c257cfec8295feed.tar.gz dexon-solidity-42289b642ff12d9275dedf10c257cfec8295feed.tar.bz2 dexon-solidity-42289b642ff12d9275dedf10c257cfec8295feed.tar.lz dexon-solidity-42289b642ff12d9275dedf10c257cfec8295feed.tar.xz dexon-solidity-42289b642ff12d9275dedf10c257cfec8295feed.tar.zst dexon-solidity-42289b642ff12d9275dedf10c257cfec8295feed.zip |
Merge pull request #4003 from ethereum/bool_vars_comparison
BREAKING: Bool variables should not allow arithmetic comparison
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SMTChecker.cpp | 29 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/types/bool_ops.sol | 53 |
2 files changed, 53 insertions, 29 deletions
diff --git a/test/libsolidity/SMTChecker.cpp b/test/libsolidity/SMTChecker.cpp index beb933a4..10f64a7f 100644 --- a/test/libsolidity/SMTChecker.cpp +++ b/test/libsolidity/SMTChecker.cpp @@ -388,35 +388,6 @@ BOOST_AUTO_TEST_CASE(bool_simple) } )"; CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function f(bool x) public pure { - bool y; - assert(x <= y); - } - } - )"; - CHECK_WARNING(text, "Assertion violation happens here"); - text = R"( - contract C { - function f(bool x) public pure { - bool y; - assert(x >= y); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); - text = R"( - contract C { - function f(bool x) public pure { - require(x); - bool y; - assert(x > y); - assert(y < x); - } - } - )"; - CHECK_SUCCESS_NO_WARNINGS(text); } BOOST_AUTO_TEST_CASE(bool_int_mixed) diff --git a/test/libsolidity/syntaxTests/types/bool_ops.sol b/test/libsolidity/syntaxTests/types/bool_ops.sol new file mode 100644 index 00000000..91033906 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/bool_ops.sol @@ -0,0 +1,53 @@ +contract C { + function f(bool a, bool b) public pure { + bool c; + // OK + c = !a; + c = !b; + c = a == b; + c = a != b; + c = a || b; + c = a && b; + + // Not OK + c = a > b; + c = a < b; + c = a >= b; + c = a <= b; + c = a & b; + c = a | b; + c = a ^ b; + c = ~a; + c = ~b; + c = a + b; + c = a - b; + c = -a; + c = -b; + c = a * b; + c = a / b; + c = a ** b; + c = a % b; + c = a << b; + c = a >> b; + } +} +// ---- +// TypeError: (231-236): Operator > not compatible with types bool and bool +// TypeError: (250-255): Operator < not compatible with types bool and bool +// TypeError: (269-275): Operator >= not compatible with types bool and bool +// TypeError: (289-295): Operator <= not compatible with types bool and bool +// TypeError: (309-314): Operator & not compatible with types bool and bool +// TypeError: (328-333): Operator | not compatible with types bool and bool +// TypeError: (347-352): Operator ^ not compatible with types bool and bool +// TypeError: (366-368): Unary operator ~ cannot be applied to type bool +// TypeError: (382-384): Unary operator ~ cannot be applied to type bool +// TypeError: (398-403): Operator + not compatible with types bool and bool +// TypeError: (417-422): Operator - not compatible with types bool and bool +// TypeError: (436-438): Unary operator - cannot be applied to type bool +// TypeError: (452-454): Unary operator - cannot be applied to type bool +// TypeError: (468-473): Operator * not compatible with types bool and bool +// TypeError: (487-492): Operator / not compatible with types bool and bool +// TypeError: (506-512): Operator ** not compatible with types bool and bool +// TypeError: (526-531): Operator % not compatible with types bool and bool +// TypeError: (545-551): Operator << not compatible with types bool and bool +// TypeError: (565-571): Operator >> not compatible with types bool and bool |