From 6d26ad1e61cd6d711332cf3f9df87917157b6a3f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 23 Apr 2018 14:56:40 +0100 Subject: Extract subdenomination tests --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 19 ------------------- .../denominations/combining_hex_and_denomination.sol | 5 +++++ .../combining_hex_and_denomination_050.sol | 6 ++++++ 3 files changed, 11 insertions(+), 19 deletions(-) create mode 100644 test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol create mode 100644 test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 3081b8f2..a2540302 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2278,25 +2278,6 @@ BOOST_AUTO_TEST_CASE(explicit_conversion_from_decimal_to_bytesxx) CHECK_SUCCESS_NO_WARNINGS(text); } -BOOST_AUTO_TEST_CASE(combining_hex_and_denomination) -{ - char const* text = R"( - contract Foo { - uint constant x = 0x01 wei; - } - )"; - CHECK_WARNING(text, "Hexadecimal numbers with unit denominations are deprecated."); - - char const* textV050 = R"( - pragma experimental "v0.5.0"; - - contract Foo { - uint constant x = 0x01 wei; - } - )"; - CHECK_ERROR(textV050, TypeError, "Hexadecimal numbers cannot be used with unit denominations."); -} - BOOST_AUTO_TEST_CASE(assigning_value_to_const_variable) { char const* text = R"( diff --git a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol new file mode 100644 index 00000000..3571e8a9 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol @@ -0,0 +1,5 @@ +contract C { + uint constant x = 0x01 wei; +} +// ---- +// Warning: (32-40): Hexadecimal numbers with unit denominations are deprecated. You can use an expression of the form "0x1234 * 1 day" instead. diff --git a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol new file mode 100644 index 00000000..98865999 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol @@ -0,0 +1,6 @@ +pragma experimental "v0.5.0"; +contract C { + uint constant x = 0x01 wei; +} +// ---- +// TypeError: (62-70): Hexadecimal numbers cannot be used with unit denominations. You can use an expression of the form "0x1234 * 1 day" instead. -- cgit v1.2.3 From 75faed7c55a45770b6b56fa9fe2be308604030a0 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 23 Apr 2018 15:04:43 +0100 Subject: Add more denomination tests --- test/libsolidity/syntaxTests/denominations/denominations.sol | 5 +++++ test/libsolidity/syntaxTests/denominations/fixed_point_division.sol | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 test/libsolidity/syntaxTests/denominations/denominations.sol create mode 100644 test/libsolidity/syntaxTests/denominations/fixed_point_division.sol diff --git a/test/libsolidity/syntaxTests/denominations/denominations.sol b/test/libsolidity/syntaxTests/denominations/denominations.sol new file mode 100644 index 00000000..de9f73e1 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/denominations.sol @@ -0,0 +1,5 @@ +contract C { + uint constant a = 1 wei + 2 szabo + 3 finney + 4 ether; + uint constant b = 1 seconds + 2 minutes + 3 hours + 4 days + 5 weeks + 6 years; + uint constant c = 2 szabo / 1 seconds + 3 finney * 3 hours; +} diff --git a/test/libsolidity/syntaxTests/denominations/fixed_point_division.sol b/test/libsolidity/syntaxTests/denominations/fixed_point_division.sol new file mode 100644 index 00000000..22331b51 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/fixed_point_division.sol @@ -0,0 +1,6 @@ +contract C { + uint constant a = 4 ether / 3 hours; + ufixed constant b = ufixed(4 ether / 3 hours); +} +// ---- +// TypeError: (32-49): Type rational_const 10000000000000000 / 27 is not implicitly convertible to expected type uint256. Try converting to type ufixed256x62 or use an explicit conversion. -- cgit v1.2.3 From 1ac0090f31d12a720950991ab4e85710877effd1 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 23 Apr 2018 14:54:45 +0100 Subject: The "year" denomination is deprecated --- Changelog.md | 1 + libsolidity/analysis/TypeChecker.cpp | 16 ++++++++++++++++ .../syntaxTests/denominations/denominations.sol | 2 ++ .../syntaxTests/denominations/deprecated_year.sol | 5 +++++ .../syntaxTests/denominations/deprecated_year_050.sol | 6 ++++++ 5 files changed, 30 insertions(+) create mode 100644 test/libsolidity/syntaxTests/denominations/deprecated_year.sol create mode 100644 test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol diff --git a/Changelog.md b/Changelog.md index f51bd634..4787f1c8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ Features: * Build System: Update internal dependency of jsoncpp to 1.8.4, which introduces more strictness and reduces memory usage. * Optimizer: Remove unnecessary masking of the result of known short instructions (``ADDRESS``, ``CALLER``, ``ORIGIN`` and ``COINBASE``). + * Type Checker: Deprecate the ``years`` unit denomination and raise a warning for it (or an error as experimental 0.5.0 feature). * Type Checker: Make literals (without explicit type casting) an error for tight packing as experimental 0.5.0 feature. Bugfixes: diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 40162322..a672cd66 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2220,6 +2220,7 @@ void TypeChecker::endVisit(Literal const& _literal) "For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals" ); } + if (_literal.isHexNumber() && _literal.subDenomination() != Literal::SubDenomination::None) { if (v050) @@ -2235,6 +2236,21 @@ void TypeChecker::endVisit(Literal const& _literal) "You can use an expression of the form \"0x1234 * 1 day\" instead." ); } + + if (_literal.subDenomination() == Literal::SubDenomination::Year) + { + if (v050) + m_errorReporter.typeError( + _literal.location(), + "Using \"years\" as a unit denomination is deprecated." + ); + else + m_errorReporter.warning( + _literal.location(), + "Using \"years\" as a unit denomination is deprecated." + ); + } + if (!_literal.annotation().type) _literal.annotation().type = Type::forLiteral(_literal); diff --git a/test/libsolidity/syntaxTests/denominations/denominations.sol b/test/libsolidity/syntaxTests/denominations/denominations.sol index de9f73e1..6d1aa2f3 100644 --- a/test/libsolidity/syntaxTests/denominations/denominations.sol +++ b/test/libsolidity/syntaxTests/denominations/denominations.sol @@ -3,3 +3,5 @@ contract C { uint constant b = 1 seconds + 2 minutes + 3 hours + 4 days + 5 weeks + 6 years; uint constant c = 2 szabo / 1 seconds + 3 finney * 3 hours; } +// ---- +// Warning: (142-149): Using "years" as a unit denomination is deprecated. diff --git a/test/libsolidity/syntaxTests/denominations/deprecated_year.sol b/test/libsolidity/syntaxTests/denominations/deprecated_year.sol new file mode 100644 index 00000000..30e86535 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/deprecated_year.sol @@ -0,0 +1,5 @@ +contract C { + uint constant a = 3 years; +} +// ---- +// Warning: (32-39): Using "years" as a unit denomination is deprecated. diff --git a/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol b/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol new file mode 100644 index 00000000..4baaeaa3 --- /dev/null +++ b/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol @@ -0,0 +1,6 @@ +pragma experimental "v0.5.0"; +contract C { + uint constant a = 3 years; +} +// ---- +// TypeError: (62-69): Using "years" as a unit denomination is deprecated. -- cgit v1.2.3