Skip to content

Commit

Permalink
Backport "Harden skip in Scanner" to LTS (#22136)
Browse files Browse the repository at this point in the history
Backports #21607 to the 3.3.5.

PR submitted by the release tooling.
  • Loading branch information
WojciechMazur authored Dec 4, 2024
2 parents 3ceb17d + 67b2cec commit 64c2968
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,15 @@ object Scanners {
println(s"\nSTART SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
var noProgress = 0
// Defensive measure to ensure we always get out of the following while loop
// even if source file is weirly formatted (i.e. we never reach EOF
// even if source file is weirly formatted (i.e. we never reach EOF)
var prevOffset = offset
while !atStop && noProgress < 3 do
val prevOffset = offset
nextToken()
if offset == prevOffset then noProgress += 1 else noProgress = 0
if offset <= prevOffset then
noProgress += 1
else
prevOffset = offset
noProgress = 0
if debugTokenStream then
println(s"\nSTOP SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
if token == OUTDENT then dropUntil(_.isInstanceOf[Indented])
Expand Down

0 comments on commit 64c2968

Please sign in to comment.