diff options
author | chriseth <chris@ethereum.org> | 2017-06-26 15:49:45 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-06-28 21:02:25 +0800 |
commit | c3e5d6b7ef64f7924754d1b0a1c5577e038e7bf4 (patch) | |
tree | 4bd915cb0c24ee403e4bd54d258b5695ac7ac120 | |
parent | a895f2dccb7f0dc22a01bd97fbf15e568deb38b0 (diff) | |
download | dexon-solidity-c3e5d6b7ef64f7924754d1b0a1c5577e038e7bf4.tar.gz dexon-solidity-c3e5d6b7ef64f7924754d1b0a1c5577e038e7bf4.tar.zst dexon-solidity-c3e5d6b7ef64f7924754d1b0a1c5577e038e7bf4.zip |
Give min and max values in warning message.
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 10 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 22 |
2 files changed, 29 insertions, 3 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 1c91a2b0..b276a2d4 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -964,9 +964,17 @@ bool TypeChecker::visit(VariableDeclarationStatement const& _statement) { int numBits = type->numBits(); bool isSigned = type->isSigned(); + string minValue; + string maxValue; if (isSigned) + { numBits--; - extension = ", which can hold values up to " + string((u256(1) << numBits) - 1); + minValue = "-" + bigint(bigint(1) << numBits).str(); + } + else + minValue = "0"; + maxValue = bigint((bigint(1) << numBits) - 1).str(); + extension = ", which can hold values between " + minValue + " and " + maxValue; } else solAssert(dynamic_cast<FixedPointType const*>(var.annotation().type.get()), "Unknown type."); diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 3d6104db..169b33d1 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1798,14 +1798,32 @@ BOOST_AUTO_TEST_CASE(warn_var_from_zero) } } )"; - CHECK_WARNING(sourceCode, "uint8, which can hold"); + CHECK_WARNING(sourceCode, "uint8, which can hold values between 0 and 255"); + sourceCode = R"( + contract test { + function f() { + var i = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; + i; + } + } + )"; + CHECK_WARNING(sourceCode, "uint256, which can hold values between 0 and 115792089237316195423570985008687907853269984665640564039457584007913129639935"); + sourceCode = R"( + contract test { + function f() { + var i = -2; + i; + } + } + )"; + CHECK_WARNING(sourceCode, "int8, which can hold values between -128 and 127"); sourceCode = R"( contract test { function f() { for (var i = 0; i < msg.data.length; i++) { } } } - )"; + )"; CHECK_WARNING(sourceCode, "uint8, which can hold"); } |