From bd4c2b9bde02b94d367ad9af6e44b9434bb1bb93 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 1 Mar 2018 16:58:20 +0100 Subject: Deprecate using unit denominations in combination with hex numbers. Closes #3574. --- libsolidity/analysis/TypeChecker.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 2914472a..4ff0fb8f 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2021,6 +2021,8 @@ 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()) { if (_literal.passesAddressChecksum()) @@ -2034,6 +2036,19 @@ 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) + m_errorReporter.fatalTypeError( + _literal.location(), + "Hexadecimal numbers cannot be used with unit denominations." + ); + else + m_errorReporter.warning( + _literal.location(), + "Hexadecimal numbers with unit denominations are deprecated." + ); + } if (!_literal.annotation().type) _literal.annotation().type = Type::forLiteral(_literal); -- cgit v1.2.3 From 454b470ceed799cb22ceaef6ea2b0bbea7165df9 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Fri, 2 Mar 2018 10:20:56 +0100 Subject: Suggest expressions of the form '0x1234 * 1 day' instead of hex numbers with unit denominations. --- libsolidity/analysis/TypeChecker.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 4ff0fb8f..cc7492dd 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2041,12 +2041,14 @@ void TypeChecker::endVisit(Literal const& _literal) if (v050) m_errorReporter.fatalTypeError( _literal.location(), - "Hexadecimal numbers cannot be used with unit denominations." + "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." + "Hexadecimal numbers with unit denominations are deprecated. " + "You can use an expression of the form '0x1234 * 1 day' instead." ); } if (!_literal.annotation().type) -- cgit v1.2.3