diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index 742d2ee2a..05ce6ed66 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -910,6 +910,28 @@ BOOST_AUTO_TEST_CASE(disallow_declaration_of_void_type) BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); } +BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units) +{ + char const* sourceCodeFine = R"( + contract c { + function c () + { + a = 115792089237316195423570985008687907853269984665640564039458; + } + uint256 a; + })"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCodeFine)); + char const* sourceCode = R"( + contract c { + function c () + { + a = 115792089237316195423570985008687907853269984665640564039458 ether; + } + uint256 a; + })"; + BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/SolidityParser.cpp b/SolidityParser.cpp index b6837866c..7af99567b 100644 --- a/SolidityParser.cpp +++ b/SolidityParser.cpp @@ -679,6 +679,19 @@ BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations) BOOST_CHECK_NO_THROW(parseTextExplainError(text)); } +BOOST_AUTO_TEST_CASE(literal_constants_with_ether_subdenominations_in_expressions) +{ + char const* text = R"( + contract c { + function c () + { + a = 1 wei * 100 wei + 7 szabo - 3; + } + uint256 a; + })"; + BOOST_CHECK_NO_THROW(parseTextExplainError(text)); +} + BOOST_AUTO_TEST_SUITE_END() }