Skip to content

Commit 5332a12

Browse files
authored
Merge pull request #15421 from dotty-staging/fix-parser-loop
Fix loop in parser
2 parents 1e09221 + 59556fd commit 5332a12

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,14 +2738,13 @@ object Parsers {
27382738
def pattern3(): Tree =
27392739
val p = infixPattern()
27402740
if followingIsVararg() then
2741-
atSpan(in.skipToken()) {
2742-
p match
2743-
case p @ Ident(name) if name.isVarPattern =>
2744-
Typed(p, Ident(tpnme.WILDCARD_STAR))
2745-
case _ =>
2746-
syntaxError(em"`*` must follow pattern variable")
2747-
p
2748-
}
2741+
val start = in.skipToken()
2742+
p match
2743+
case p @ Ident(name) if name.isVarPattern =>
2744+
Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) })
2745+
case _ =>
2746+
syntaxError(em"`*` must follow pattern variable", start)
2747+
p
27492748
else p
27502749

27512750
/** Pattern2 ::= [id `@'] Pattern3

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,13 @@ object Scanners {
313313
// when skipping and therefore might erroneously end up syncing on a nested OUTDENT.
314314
if debugTokenStream then
315315
println(s"\nSTART SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
316-
while !atStop do
316+
var noProgress = 0
317+
// Defensive measure to ensure we always get out of the following while loop
318+
// even if source file is weirly formatted (i.e. we never reach EOF
319+
while !atStop && noProgress < 3 do
320+
val prevOffset = offset
317321
nextToken()
322+
if offset == prevOffset then noProgress += 1 else noProgress = 0
318323
if debugTokenStream then
319324
println(s"\nSTOP SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
320325
if token == OUTDENT then dropUntil(_.isInstanceOf[Indented])

0 commit comments

Comments
 (0)