Skip to content

Commit e5fd587

Browse files
committed
Improve error recovery after illegal :
Some users might write things like `then:` by accident. In this case we should report an error, skip the `:`, and continue. No skip ahead to an anchor token is wanted.
1 parent 0bd9739 commit e5fd587

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,11 +2246,15 @@ object Parsers {
22462246
val start = in.skipToken()
22472247
MacroTree(simpleExpr(Location.ElseWhere))
22482248
case _ =>
2249-
if (isLiteral) literal()
2250-
else {
2249+
if isLiteral then
2250+
literal()
2251+
else if in.isColon() then
2252+
syntaxError(IllegalStartSimpleExpr(tokenString(in.token)))
2253+
in.nextToken()
2254+
simpleExpr(location)
2255+
else
22512256
syntaxErrorOrIncomplete(IllegalStartSimpleExpr(tokenString(in.token)), expectedOffset)
22522257
errorTermTree
2253-
}
22542258
}
22552259
simpleExprRest(t, location, canApply)
22562260
}

0 commit comments

Comments
 (0)