Merge pull request #3628 from ethereum/literalsHexUnit

Deprecate using unit denominations in combination with hex numbers.
This commit is contained in:
chriseth 2018-03-02 11:11:16 +01:00 committed by GitHub
commit f78d6a9a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -9,6 +9,7 @@ Features:
* Syntax Analyser: Do not warn about experimental features if they do not concern code generation. * Syntax Analyser: Do not warn about experimental features if they do not concern code generation.
* Syntax Checker: Mark ``throw`` as an error as experimental 0.5.0 feature. * Syntax Checker: Mark ``throw`` as an error as experimental 0.5.0 feature.
* Syntax Checker: Issue error if no visibility is specified on contract functions as experimental 0.5.0 feature. * Syntax Checker: Issue error if no visibility is specified on contract functions as experimental 0.5.0 feature.
* Type Checker: disallow combining hex numbers and unit denominations as experimental 0.5.0 feature.
Bugfixes: Bugfixes:
* Assembly: Raise error on oversized number literals in assembly. * Assembly: Raise error on oversized number literals in assembly.

View File

@ -2021,6 +2021,8 @@ void TypeChecker::endVisit(ElementaryTypeNameExpression const& _expr)
void TypeChecker::endVisit(Literal const& _literal) void TypeChecker::endVisit(Literal const& _literal)
{ {
bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
if (_literal.looksLikeAddress()) if (_literal.looksLikeAddress())
{ {
if (_literal.passesAddressChecksum()) if (_literal.passesAddressChecksum())
@ -2034,6 +2036,21 @@ void TypeChecker::endVisit(Literal const& _literal)
"For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals" "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. "
"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."
);
}
if (!_literal.annotation().type) if (!_literal.annotation().type)
_literal.annotation().type = Type::forLiteral(_literal); _literal.annotation().type = Type::forLiteral(_literal);

View File

@ -2717,6 +2717,25 @@ BOOST_AUTO_TEST_CASE(explicit_conversion_from_decimal_to_bytesxx)
CHECK_SUCCESS_NO_WARNINGS(text); 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) BOOST_AUTO_TEST_CASE(assigning_value_to_const_variable)
{ {
char const* text = R"( char const* text = R"(