Merge pull request #4684 from ethereum/underscores_in_numeric_literals

[BREAKING] Underscores in numeric literals
This commit is contained in:
chriseth
2018-08-08 21:36:57 +02:00
committed by GitHub
15 changed files with 256 additions and 14 deletions
@@ -0,0 +1,13 @@
contract C {
function f() public pure {
uint d1 = 654_321;
uint d2 = 54_321;
uint d3 = 4_321;
uint d4 = 5_43_21;
uint d5 = 1_2e10;
uint d6 = 12e1_0;
d1; d2; d3; d4; d5; d6;
}
}
// ----
@@ -0,0 +1,13 @@
contract C {
function f() public pure {
uint D1 = 1234_;
uint D2 = 12__34;
uint D3 = 12_e34;
uint D4 = 12e_34;
}
}
// ----
// SyntaxError: (56-61): Invalid use of underscores in number literal. No trailing underscores allowed.
// SyntaxError: (77-83): Invalid use of underscores in number literal. Only one consecutive underscores between digits allowed.
// SyntaxError: (99-105): Invalid use of underscores in number literal. No underscore at the end of the mantissa allowed.
// SyntaxError: (121-127): Invalid use of underscores in number literal. No underscore in front of exponent allowed.
@@ -0,0 +1,9 @@
contract C {
function f() public pure {
fixed f1 = 3.14_15;
fixed f2 = 3_1.4_15;
f1; f2;
}
}
// ----
@@ -0,0 +1,17 @@
contract C {
function f() public pure {
fixed F1 = 3.1415_;
fixed F2 = 3__1.4__15;
fixed F3 = 1_.2;
fixed F4 = 1._2;
fixed F5 = 1.2e_12;
fixed F6 = 1._;
}
}
// ----
// SyntaxError: (57-64): Invalid use of underscores in number literal. No trailing underscores allowed.
// SyntaxError: (81-91): Invalid use of underscores in number literal. Only one consecutive underscores between digits allowed.
// SyntaxError: (108-112): Invalid use of underscores in number literal. No underscores in front of the fraction part allowed.
// SyntaxError: (129-133): Invalid use of underscores in number literal. No underscores in front of the fraction part allowed.
// SyntaxError: (150-157): Invalid use of underscores in number literal. No underscore in front of exponent allowed.
// SyntaxError: (174-177): Invalid use of underscores in number literal. No trailing underscores allowed.
@@ -0,0 +1,13 @@
contract C {
function f() public pure {
uint x1 = 0x8765_4321;
uint x2 = 0x765_4321;
uint x3 = 0x65_4321;
uint x4 = 0x5_4321;
uint x5 = 0x123_1234_1234_1234;
uint x6 = 0x123456_1234_1234;
x1; x2; x3; x4; x5; x6;
}
}
// ----
@@ -0,0 +1,7 @@
contract C {
function f() public pure {
uint X1 = 0x1234__1234__1234__123;
}
}
// ----
// SyntaxError: (56-79): Invalid use of underscores in number literal. Only one consecutive underscores between digits allowed.