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

ScannerTokens: keep multiple outdents to swap , #3666

Merged
merged 2 commits into from Mar 22, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -1675,6 +1675,36 @@ class SignificantIndentationSuite extends BaseDottySuite {
runTestAssert[Stat](code, layout)(tree)
}

test("#3542 apply with optional braces in intermediate arg, with multiple outdents") {
val code =
"""|A(
| foo = x =>
| x match
| case baz => baz,
| bar = bar
|)
|""".stripMargin
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") {
runTestAssert[Stat](
"""|def method =
Expand Down