Skip to content

Commit

Permalink
ScannerTokens: keep multiple outdents to swap ,
Browse files Browse the repository at this point in the history
`nextToken` ignored the `.next` field and tried to recompute the next
token; instead, we should not do that if that field is already set.
  • Loading branch information
kitbellew committed Mar 22, 2024
1 parent b866e87 commit 83a6e86
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Expand Up @@ -21,9 +21,9 @@ private[parsers] class LazyTokenIterator private (

import scannerTokens._

private def getNextTokenRef(): TokenRef = {
if (curr.next eq null) nextToken(curr) else curr.next
}
@inline
private def getNextTokenRef(): TokenRef =
nextToken(curr)

override def next(): Unit = {
prev = curr
Expand Down
Expand Up @@ -325,15 +325,16 @@ final class ScannerTokens(val tokens: Tokens)(implicit dialect: Dialect) {
}
}

@inline
private[parsers] def nextToken(ref: TokenRef): TokenRef = {
val next = nextToken(ref.token, ref.pos, ref.nextPos, ref.regions)
ref.next = next
next
private[parsers] def nextToken(ref: TokenRef): TokenRef = ref.next match {
case null =>
val next = nextToken(ref.token, ref.pos, ref.nextPos, ref.regions)
ref.next = next
next
case nref => nref
}

@tailrec
private[parsers] def nextToken(
private def nextToken(
prevToken: Token,
prevPos: Int,
currPos: Int,
Expand Down
Expand Up @@ -1684,11 +1684,25 @@ class SignificantIndentationSuite extends BaseDottySuite {
| bar = bar
|)
|""".stripMargin
val error =
"""|<input>:4: error: `;` expected but `,` found
| case baz => baz,
| ^""".stripMargin
runTestError[Stat](code, error)
val layout =
"""|A(foo = x => x match {
| case baz => baz
|}, bar = bar)
|""".stripMargin
val tree = Term.Apply(
tname("A"),
List(
Term.Assign(
tname("foo"),
Term.Function(
List(tparam("x")),
Term.Match(tname("x"), List(Case(Pat.Var(tname("baz")), None, tname("baz"))), Nil)
)
),
Term.Assign(tname("bar"), tname("bar"))
)
)
runTestAssert[Stat](code, layout)(tree)
}

test("indented-double-apply") {
Expand Down

0 comments on commit 83a6e86

Please sign in to comment.