Skip to content

Commit 11d533a

Browse files
committed
Add java examples and fix uncovered underscore case in hex literals
Removed redundant test cases https://docs.oracle.com/javase/8/docs/technotes/guides/language/underscores-literals.html
1 parent 12d5f3d commit 11d533a

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ object Scanners {
508508
if (ch == 'x' || ch == 'X') {
509509
nextChar()
510510
base = 16
511+
if (isNumberSeparator(ch))
512+
errorButContinue("leading separator is not allowed", offset + 2)
511513
} else {
512514
/**
513515
* What should leading 0 be in the future? It is potentially dangerous

tests/neg/t6124.check

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1-
<304..304> in t6124.scala
2-
double precision floating point number too small
3-
<273..273> in t6124.scala
1+
[490..493] in t6124.scala
2+
Not found: _52
3+
[404..406..412] in t6124.scala
4+
value _1415F is not a member of Int
5+
<594..594> in t6124.scala
46
trailing separator is not allowed
5-
<235..235> in t6124.scala
6-
Invalid literal number
7-
<240..240> in t6124.scala
7+
<567..567> in t6124.scala
8+
leading separator is not allowed
9+
<540..540> in t6124.scala
810
trailing separator is not allowed
9-
<213..213> in t6124.scala
11+
<516..516> in t6124.scala
1012
trailing separator is not allowed
11-
<187..187> in t6124.scala
13+
<467..467> in t6124.scala
1214
trailing separator is not allowed
13-
<160..160> in t6124.scala
15+
<375..375> in t6124.scala
16+
trailing separator is not allowed
17+
<228..228> in t6124.scala
18+
double precision floating point number too small
19+
<197..197> in t6124.scala
1420
trailing separator is not allowed
15-
<125..125> in t6124.scala
21+
<159..159> in t6124.scala
1622
Invalid literal number
17-
<101..101> in t6124.scala
23+
<164..164> in t6124.scala
1824
trailing separator is not allowed
19-
<67..67> in t6124.scala
25+
<137..137> in t6124.scala
2026
trailing separator is not allowed
21-
<33..33> in t6124.scala
27+
<111..111> in t6124.scala
28+
trailing separator is not allowed
29+
<84..84> in t6124.scala
30+
trailing separator is not allowed
31+
<49..49> in t6124.scala
32+
Invalid literal number
33+
<25..25> in t6124.scala
2234
trailing separator is not allowed

tests/neg/t6124.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

22
trait T {
3-
def i: Int = 123_456_ // error
4-
def j: Long = 123_456_L * 1000 // error
5-
63
def f = 3_14_E-2 // error
74
def e = 3_14E-_2 // error
85
def d = 3_14E-2_ // error
@@ -14,5 +11,19 @@ trait T {
1411

1512
def tooSmall = 1.0E-325 // error
1613

14+
// Examples from
15+
// https://docs.oracle.com/javase/8/docs/technotes/guides/language/underscores-literals.html
16+
17+
val pi1 = 3_.1415F // error
18+
val pi2 = 3._1415F // error
19+
val socialSecurityNumber1
20+
= 999_99_9999_L // error
21+
val x1 = _52 // error
22+
val x3 = 52_ // error
23+
24+
val x5 = 0_x52 // error
25+
val x6 = 0x_52 // error
26+
val x8 = 0x52_ // error
27+
1728
def z = 0
1829
}

tests/pos/t6124.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ trait T {
88
def d = 3_14E-2_1
99

1010
def z = 0
11+
12+
13+
// Examples from
14+
// https://docs.oracle.com/javase/8/docs/technotes/guides/language/underscores-literals.html
15+
val x2 = 5_2; // OK (decimal literal)
16+
val x4 = 5_______2; // OK (decimal literal)
17+
val x7 = 0x5_2; // OK (hexadecimal literal)
1118
}

0 commit comments

Comments
 (0)