mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow octal literals.
This commit is contained in:
parent
573b885337
commit
bb06569dc6
@ -197,10 +197,9 @@ Rational and Integer Literals
|
|||||||
|
|
||||||
Integer literals are formed from a sequence of numbers in the range 0-9.
|
Integer literals are formed from a sequence of numbers in the range 0-9.
|
||||||
They are interpreted as decimals. For example, ``69`` means sixty nine.
|
They are interpreted as decimals. For example, ``69`` means sixty nine.
|
||||||
Octal literals do not exist in Solidity and leading zeros are ignored.
|
Octal literals do not exist in Solidity and leading zeros are invalid.
|
||||||
For example, ``0100`` means one hundred.
|
|
||||||
|
|
||||||
Decimal literals are formed by a ``.`` with at least one number on
|
Decimal fraction literals are formed by a ``.`` with at least one number on
|
||||||
one side. Examples include ``1.``, ``.1`` and ``1.3``.
|
one side. Examples include ``1.``, ``.1`` and ``1.3``.
|
||||||
|
|
||||||
Number literal expressions retain arbitrary precision until they are converted to a non-literal type (i.e. by
|
Number literal expressions retain arbitrary precision until they are converted to a non-literal type (i.e. by
|
||||||
|
@ -758,6 +758,9 @@ Token::Value Scanner::scanNumber(char _charSeen)
|
|||||||
while (isHexDigit(m_char))
|
while (isHexDigit(m_char))
|
||||||
addLiteralCharAndAdvance();
|
addLiteralCharAndAdvance();
|
||||||
}
|
}
|
||||||
|
else if (isDecimalDigit(m_char))
|
||||||
|
// We do not allow octal numbers
|
||||||
|
return Token::Illegal;
|
||||||
}
|
}
|
||||||
// Parse decimal digits and allow trailing fractional part.
|
// Parse decimal digits and allow trailing fractional part.
|
||||||
if (kind == DECIMAL)
|
if (kind == DECIMAL)
|
||||||
|
@ -97,6 +97,24 @@ BOOST_AUTO_TEST_CASE(hex_numbers)
|
|||||||
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
|
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(octal_numbers)
|
||||||
|
{
|
||||||
|
Scanner scanner(CharStream("07"));
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
|
||||||
|
scanner.reset(CharStream("007"), "");
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Illegal);
|
||||||
|
scanner.reset(CharStream("-07"), "");
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Sub);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
|
||||||
|
scanner.reset(CharStream("-.07"), "");
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Sub);
|
||||||
|
BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
|
||||||
|
scanner.reset(CharStream("0"), "");
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number);
|
||||||
|
scanner.reset(CharStream("0.1"), "");
|
||||||
|
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(negative_numbers)
|
BOOST_AUTO_TEST_CASE(negative_numbers)
|
||||||
{
|
{
|
||||||
Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9;"));
|
Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9;"));
|
||||||
|
Loading…
Reference in New Issue
Block a user