Skip to content

Commit c9abf03

Browse files
committed
Avoid skip on numeric literal badly decoded
Align with Scala 2 and improve subsequent parsing.
1 parent 3be948b commit c9abf03

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
@@ -1116,9 +1116,9 @@ object Parsers {
11161116
case EXPOLIT => return Number(digits, NumberKind.Floating)
11171117
case _ =>
11181118
}
1119-
import scala.util.FromDigits._
1119+
import scala.util.FromDigits.*
11201120
val value =
1121-
try token match {
1121+
try token match
11221122
case INTLIT => intFromDigits(digits, in.base)
11231123
case LONGLIT => longFromDigits(digits, in.base)
11241124
case FLOATLIT => floatFromDigits(digits)
@@ -1128,15 +1128,11 @@ object Parsers {
11281128
case TRUE => true
11291129
case FALSE => false
11301130
case NULL => null
1131-
case _ =>
1132-
syntaxErrorOrIncomplete(IllegalLiteral())
1133-
null
1134-
}
1135-
catch {
1136-
case ex: FromDigitsException => syntaxErrorOrIncomplete(ex.getMessage)
1137-
}
1131+
case _ => syntaxErrorOrIncomplete(IllegalLiteral()); null
1132+
catch case ex: FromDigitsException => syntaxError(ex.getMessage)
11381133
Literal(Constant(value))
11391134
}
1135+
end literalOf
11401136

11411137
if (inStringInterpolation) {
11421138
val t = in.token match {
@@ -1186,6 +1182,7 @@ object Parsers {
11861182
}
11871183
}
11881184
}
1185+
end literal
11891186

11901187
private def interpolatedString(inPattern: Boolean = false): Tree = atSpan(in.offset) {
11911188
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)