Skip to content

Commit 0c074b0

Browse files
committed
Avoid skip on numeric literal badly decoded
Align with Scala 2 and improve subsequent parsing.
1 parent cff1907 commit 0c074b0

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -1182,9 +1182,9 @@ object Parsers {
11821182
case EXPOLIT => return Number(digits, NumberKind.Floating)
11831183
case _ =>
11841184
}
1185-
import scala.util.FromDigits._
1185+
import scala.util.FromDigits.*
11861186
val value =
1187-
try token match {
1187+
try token match
11881188
case INTLIT => intFromDigits(digits, in.base)
11891189
case LONGLIT => longFromDigits(digits, in.base)
11901190
case FLOATLIT => floatFromDigits(digits)
@@ -1194,15 +1194,11 @@ object Parsers {
11941194
case TRUE => true
11951195
case FALSE => false
11961196
case NULL => null
1197-
case _ =>
1198-
syntaxErrorOrIncomplete(IllegalLiteral())
1199-
null
1200-
}
1201-
catch {
1202-
case ex: FromDigitsException => syntaxErrorOrIncomplete(ex.getMessage)
1203-
}
1197+
case _ => syntaxErrorOrIncomplete(IllegalLiteral()); null
1198+
catch case ex: FromDigitsException => syntaxError(ex.getMessage)
12041199
Literal(Constant(value))
12051200
}
1201+
end literalOf
12061202

12071203
if (inStringInterpolation) {
12081204
val t = in.token match {
@@ -1252,6 +1248,7 @@ object Parsers {
12521248
}
12531249
}
12541250
}
1251+
end literal
12551252

12561253
private def interpolatedString(inPattern: Boolean = false): Tree = atSpan(in.offset) {
12571254
val segmentBuf = new ListBuffer[Tree]

tests/neg/literals.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ trait MoreSadness {
4242
def tooHuge: Float = { 3.4028236E38f } // error: floating point number too large
4343

4444
def twoHuge: Double = { 1.7976931348623159e308 } // error: double precision floating point number too large
45-
} // error: Found: Unit etc, sad
45+
}
4646

4747
trait Lengthy {
4848

4949
def bad = 1l
5050

5151
def worse = 123l
52-
} // error: Found: Unit etc, sad // anypos-error: '}' expected, but eof found, sad
52+
}

0 commit comments

Comments
 (0)