Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ object Scanners {
* to let it be base-10 because of history. Should it be an error? Is
* there a realistic situation where one would need it?
*/
if (isDigit(ch))
if (isDigit(ch) || (isNumberSeparator(ch) && isDigit(lookaheadChar())))
error("Non-zero numbers may not have a leading zero.")
base = 10
}
Expand Down
14 changes: 6 additions & 8 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ idrest ::= {letter | digit} [‘_’ op]
quoteId ::= ‘'’ alphaid

integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’]
decimalNumeral ::= ‘0’ | nonZeroDigit {digit}
hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit {hexDigit}
digit ::= ‘0’ | nonZeroDigit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this digit is a duplicate definition

decimalNumeral ::= ‘0’ | nonZeroDigit [{digit | ‘_’} digit]
hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit [{hexDigit | ‘_’} hexDigit]
nonZeroDigit ::= ‘1’ | … | ‘9’

floatingPointLiteral
::= digit {digit} ‘.’ {digit} [exponentPart] [floatType]
| ‘.’ digit {digit} [exponentPart] [floatType]
| digit {digit} exponentPart [floatType]
| digit {digit} [exponentPart] floatType
exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit {digit}
::= [decimalNumeral] ‘.’ digit [{digit | ‘_’} digit] [exponentPart] [floatType]
| decimalNumeral exponentPart [floatType]
| decimalNumeral floatType
exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit [{digit | ‘_’} digit]
floatType ::= ‘F’ | ‘f’ | ‘D’ | ‘d’

booleanLiteral ::= ‘true’ | ‘false’
Expand Down
16 changes: 16 additions & 0 deletions tests/neg/t6124.check
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@
26 | val x8 = 0x52_ // error
| ^
| trailing separator is not allowed
-- Error: tests/neg/t6124.scala:27:11 ----------------------------------------------------------------------------------
27 | val x9 = 0_52 // error
| ^
| Non-zero numbers may not have a leading zero.
-- Error: tests/neg/t6124.scala:28:12 ----------------------------------------------------------------------------------
28 | val x10 = 052 // error
| ^
| Non-zero numbers may not have a leading zero.
-- Error: tests/neg/t6124.scala:29:12 ----------------------------------------------------------------------------------
29 | val x11 = 0_0.52 // error
| ^
| Non-zero numbers may not have a leading zero.
-- Error: tests/neg/t6124.scala:30:12 ----------------------------------------------------------------------------------
30 | val x12 = 00.52 // error
| ^
| Non-zero numbers may not have a leading zero.
-- Error: tests/neg/t6124.scala:12:17 ----------------------------------------------------------------------------------
12 | def tooSmall = 1.0E-325 // error
| ^^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion tests/neg/t6124.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ trait T {
val x5 = 0_x52 // error
val x6 = 0x_52 // error
val x8 = 0x52_ // error
val x9 = 0_52 // error
val x10 = 052 // error
val x11 = 0_0.52 // error
val x12 = 00.52 // error

def z = 0
}
}