Skip to content

Commit 64c2968

Browse files
Backport "Harden skip in Scanner" to LTS (#22136)
Backports #21607 to the 3.3.5. PR submitted by the release tooling.
2 parents 3ceb17d + 67b2cec commit 64c2968

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: compiler/src/dotty/tools/dotc/parsing/Scanners.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,15 @@ object Scanners {
305305
println(s"\nSTART SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
306306
var noProgress = 0
307307
// Defensive measure to ensure we always get out of the following while loop
308-
// even if source file is weirly formatted (i.e. we never reach EOF
308+
// even if source file is weirly formatted (i.e. we never reach EOF)
309+
var prevOffset = offset
309310
while !atStop && noProgress < 3 do
310-
val prevOffset = offset
311311
nextToken()
312-
if offset == prevOffset then noProgress += 1 else noProgress = 0
312+
if offset <= prevOffset then
313+
noProgress += 1
314+
else
315+
prevOffset = offset
316+
noProgress = 0
313317
if debugTokenStream then
314318
println(s"\nSTOP SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
315319
if token == OUTDENT then dropUntil(_.isInstanceOf[Indented])

0 commit comments

Comments
 (0)