diff options
author | Federico Bond <federicobond@gmail.com> | 2018-03-22 12:20:50 +0800 |
---|---|---|
committer | Federico Bond <federicobond@gmail.com> | 2018-03-22 21:05:49 +0800 |
commit | b79531bebf67b84fbd2cfe90c1911ec563855afa (patch) | |
tree | c88d3e68e3b25f9a957244b73f4c9a4223a0bfb6 | |
parent | ba209fe485ba40ea3926800bc90932bec40cd16f (diff) | |
download | dexon-solidity-b79531bebf67b84fbd2cfe90c1911ec563855afa.tar.gz dexon-solidity-b79531bebf67b84fbd2cfe90c1911ec563855afa.tar.zst dexon-solidity-b79531bebf67b84fbd2cfe90c1911ec563855afa.zip |
Improve error message when trying to shift by fractional number
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/ast/Types.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 |
3 files changed, 12 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md index c5577b86..11be5b9d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ Bugfixes: * Commandline interface: Support ``--evm-version constantinople`` properly. * DocString Parser: Fix error message for empty descriptions. * Standard JSON: Support ``constantinople`` as ``evmVersion`` properly. + * Type System: Improve error message when attempting to shift by a fractional amount. * Type System: Make external library functions accessible. ### 0.4.21 (2018-03-07) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 41700e28..720215c9 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -327,7 +327,7 @@ bool isValidShiftAndAmountType(Token::Value _operator, Type const& _shiftAmountT else if (IntegerType const* otherInt = dynamic_cast<decltype(otherInt)>(&_shiftAmountType)) return !otherInt->isAddress(); else if (RationalNumberType const* otherRat = dynamic_cast<decltype(otherRat)>(&_shiftAmountType)) - return otherRat->integerType() && !otherRat->integerType()->isSigned(); + return !otherRat->isFractional() && otherRat->integerType() && !otherRat->integerType()->isSigned(); else return false; } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 50ee2b2e..ab6113dd 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5866,6 +5866,16 @@ BOOST_AUTO_TEST_CASE(shift_constant_right_excessive_rvalue) CHECK_ERROR(text, TypeError, "Operator >> not compatible with types int_const 66 and int_const 4294967296"); } +BOOST_AUTO_TEST_CASE(shift_constant_right_fractional) +{ + char const* text = R"( + contract C { + uint public a = 0x42 >> (1 / 2); + } + )"; + CHECK_ERROR(text, TypeError, "Operator >> not compatible with types int_const 66 and rational_const 1 / 2"); +} + BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_positive_stack) { char const* text = R"( |