From c1b67a845b7327e58ecf8fd8502750fbdb378e6e Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Thu, 5 Jul 2018 15:48:57 +0200 Subject: Enforce error on hex number combined with unit denomination --- Changelog.md | 1 + libsolidity/analysis/TypeChecker.cpp | 23 ++++++---------------- .../combining_hex_and_denomination.sol | 2 +- .../combining_hex_and_denomination_050.sol | 6 ------ 4 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol diff --git a/Changelog.md b/Changelog.md index 8cd0b4b7..0cb41ce4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -25,6 +25,7 @@ Breaking Changes: ``sizeof``, ``supports``, ``typedef`` and ``unchecked``. * General: Remove assembly instruction aliases ``sha3`` and ``suicide`` * General: C99-style scoping rules are enforced now. This was already the case in the experimental 0.5.0 mode. + * General: Disallow combining hex numbers with unit denominations (e.g. 0x1e wei). This was already the case in the experimental 0.5.0 mode. * Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence. * Parser: Disallow trailing dots that are not followed by a number. * Parser: Remove ``constant`` as function state mutability modifer. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 676b3cd6..ed7f05f7 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2267,11 +2267,9 @@ void TypeChecker::endVisit(ElementaryTypeNameExpression const& _expr) void TypeChecker::endVisit(Literal const& _literal) { - bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - if (_literal.looksLikeAddress()) { - // Assign type here if it even looks like an address. This prevents double error in 050 mode for invalid address + // Assign type here if it even looks like an address. This prevents double errors for invalid addresses _literal.annotation().type = make_shared(160, IntegerType::Modifier::Address); string msg; @@ -2298,20 +2296,11 @@ void TypeChecker::endVisit(Literal const& _literal) } if (_literal.isHexNumber() && _literal.subDenomination() != Literal::SubDenomination::None) - { - if (v050) - m_errorReporter.fatalTypeError( - _literal.location(), - "Hexadecimal numbers cannot be used with unit denominations. " - "You can use an expression of the form \"0x1234 * 1 day\" instead." - ); - else - m_errorReporter.warning( - _literal.location(), - "Hexadecimal numbers with unit denominations are deprecated. " - "You can use an expression of the form \"0x1234 * 1 day\" instead." - ); - } + m_errorReporter.fatalTypeError( + _literal.location(), + "Hexadecimal numbers cannot be used with unit denominations. " + "You can use an expression of the form \"0x1234 * 1 day\" instead." + ); if (_literal.subDenomination() == Literal::SubDenomination::Year) m_errorReporter.typeError( diff --git a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol index 3571e8a9..f115ac60 100644 --- a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol +++ b/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination.sol @@ -2,4 +2,4 @@ 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. +// TypeError: (32-40): Hexadecimal numbers cannot be used with unit denominations. 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 deleted file mode 100644 index 98865999..00000000 --- a/test/libsolidity/syntaxTests/denominations/combining_hex_and_denomination_050.sol +++ /dev/null @@ -1,6 +0,0 @@ -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 From 4747ef26fb752c413bf64483070a6c30584b7287 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 9 Jul 2018 17:56:53 +0200 Subject: Add backticks to changelog. --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 0cb41ce4..304f70ea 100644 --- a/Changelog.md +++ b/Changelog.md @@ -25,7 +25,7 @@ Breaking Changes: ``sizeof``, ``supports``, ``typedef`` and ``unchecked``. * General: Remove assembly instruction aliases ``sha3`` and ``suicide`` * General: C99-style scoping rules are enforced now. This was already the case in the experimental 0.5.0 mode. - * General: Disallow combining hex numbers with unit denominations (e.g. 0x1e wei). This was already the case in the experimental 0.5.0 mode. + * General: Disallow combining hex numbers with unit denominations (e.g. ``0x1e wei``). This was already the case in the experimental 0.5.0 mode. * Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence. * Parser: Disallow trailing dots that are not followed by a number. * Parser: Remove ``constant`` as function state mutability modifer. -- cgit