Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loop in parser #15421

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2745,14 +2745,13 @@ object Parsers {
def pattern3(): Tree =
val p = infixPattern()
if followingIsVararg() then
atSpan(in.skipToken()) {
p match
case p @ Ident(name) if name.isVarPattern =>
Typed(p, Ident(tpnme.WILDCARD_STAR))
case _ =>
syntaxError(em"`*` must follow pattern variable")
p
}
val start = in.skipToken()
p match
case p @ Ident(name) if name.isVarPattern =>
Typed(p, atSpan(start) { Ident(tpnme.WILDCARD_STAR) })
case _ =>
syntaxError(em"`*` must follow pattern variable", start)
p
else p

/** Pattern2 ::= [id `@'] Pattern3
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,13 @@ object Scanners {
// when skipping and therefore might erroneously end up syncing on a nested OUTDENT.
if debugTokenStream then
println(s"\nSTART SKIP AT ${sourcePos().line + 1}, $this in $currentRegion")
while !atStop do
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
while !atStop && noProgress < 3 do
val prevOffset = offset
nextToken()
if offset == prevOffset then noProgress += 1 else 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