File tree Expand file tree Collapse file tree 4 files changed +28
-10
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 4 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -695,7 +695,7 @@ object Scanners {
695
695
* to let it be base-10 because of history. Should it be an error? Is
696
696
* there a realistic situation where one would need it?
697
697
*/
698
- if (isDigit(ch))
698
+ if (isDigit(ch) || (isNumberSeparator(ch) && isDigit(lookaheadChar())) )
699
699
error(" Non-zero numbers may not have a leading zero." )
700
700
base = 10
701
701
}
Original file line number Diff line number Diff line change @@ -47,17 +47,15 @@ idrest ::= {letter | digit} [‘_’ op]
47
47
quoteId ::= ‘'’ alphaid
48
48
49
49
integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’]
50
- decimalNumeral ::= ‘0’ | nonZeroDigit {digit}
51
- hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit {hexDigit}
52
- digit ::= ‘0’ | nonZeroDigit
50
+ decimalNumeral ::= ‘0’ | nonZeroDigit [{digit | ‘_’} digit]
51
+ hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit [{hexDigit | ‘_’} hexDigit]
53
52
nonZeroDigit ::= ‘1’ | … | ‘9’
54
53
55
54
floatingPointLiteral
56
- ::= digit {digit} ‘.’ {digit} [exponentPart] [floatType]
57
- | ‘.’ digit {digit} [exponentPart] [floatType]
58
- | digit {digit} exponentPart [floatType]
59
- | digit {digit} [exponentPart] floatType
60
- exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit {digit}
55
+ ::= [decimalNumeral] ‘.’ digit [{digit | ‘_’} digit] [exponentPart] [floatType]
56
+ | decimalNumeral exponentPart [floatType]
57
+ | decimalNumeral floatType
58
+ exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit [{digit | ‘_’} digit]
61
59
floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’
62
60
63
61
booleanLiteral ::= ‘true’ | ‘false’
Original file line number Diff line number Diff line change 54
54
26 | val x8 = 0x52_ // error
55
55
| ^
56
56
| trailing separator is not allowed
57
+ -- Error: tests/neg/t6124.scala:27:11 ----------------------------------------------------------------------------------
58
+ 27 | val x9 = 0_52 // error
59
+ | ^
60
+ | Non-zero numbers may not have a leading zero.
61
+ -- Error: tests/neg/t6124.scala:28:12 ----------------------------------------------------------------------------------
62
+ 28 | val x10 = 052 // error
63
+ | ^
64
+ | Non-zero numbers may not have a leading zero.
65
+ -- Error: tests/neg/t6124.scala:29:12 ----------------------------------------------------------------------------------
66
+ 29 | val x11 = 0_0.52 // error
67
+ | ^
68
+ | Non-zero numbers may not have a leading zero.
69
+ -- Error: tests/neg/t6124.scala:30:12 ----------------------------------------------------------------------------------
70
+ 30 | val x12 = 00.52 // error
71
+ | ^
72
+ | Non-zero numbers may not have a leading zero.
57
73
-- Error: tests/neg/t6124.scala:12:17 ----------------------------------------------------------------------------------
58
74
12 | def tooSmall = 1.0E-325 // error
59
75
| ^^^^^^^^
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ trait T {
24
24
val x5 = 0_x52 // error
25
25
val x6 = 0x_52 // error
26
26
val x8 = 0x52_ // error
27
+ val x9 = 0_52 // error
28
+ val x10 = 052 // error
29
+ val x11 = 0_0.52 // error
30
+ val x12 = 00.52 // error
27
31
28
32
def z = 0
29
- }
33
+ }
You can’t perform that action at this time.
0 commit comments