Skip to content

Commit

Permalink
Merge pull request #3606 from kitbellew/3605
Browse files Browse the repository at this point in the history
ScannerTokens: yet another leading infix fix
  • Loading branch information
kitbellew committed Mar 6, 2024
2 parents 4dc1d89 + 3310146 commit 727c59c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
Expand Up @@ -950,8 +950,8 @@ final class ScannerTokens(val tokens: Tokens)(implicit dialect: Dialect) {
private def isLeadingInfixArg(afterOpPos: Int, nextIndent: Int) = {
// we don't check for pos to be within bounds since we would exit on EOF first
@tailrec def iter(pos: Int, indent: Int, prevNoNL: Boolean): LeadingInfix = tokens(pos) match {
case _: EOL => if (prevNoNL) iter(pos + 1, 0, false) else LeadingInfix.InvalidArg
case _: Whitespace => iter(pos + 1, if (prevNoNL) indent else indent + 1, prevNoNL)
case _: EOL => if (prevNoNL) iter(pos + 1, 0, false) else LeadingInfix.No
case _: HSpace => iter(pos + 1, if (prevNoNL) indent else indent + 1, prevNoNL)
case c: Comment =>
val commentIndent = multilineCommentIndent(c)
iter(pos + 1, if (commentIndent < 0) indent else commentIndent, true)
Expand All @@ -962,7 +962,7 @@ final class ScannerTokens(val tokens: Tokens)(implicit dialect: Dialect) {
}
tokens(afterOpPos) match {
case _: EOL => iter(afterOpPos + 1, 0, false)
case _: Whitespace => iter(afterOpPos + 1, -1, true)
case _: HSpace => iter(afterOpPos + 1, -1, true)
case _: Comment => LeadingInfix.InvalidArg
case _ => LeadingInfix.No
}
Expand Down
Expand Up @@ -379,6 +379,26 @@ class DefnSuite extends ParseSuite {
runTestAssert[Stat](code, layout)(tree)
}

test("#3605 scala213") {
val code =
"""|new A {
| def b: C =
| ???
|
|}
|""".stripMargin
val layout =
"""|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(
tpl(
List(Init(pname("A"), anon, Nil)),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
)
)
runTestAssert[Stat](code, layout)(tree)
}

test("#3571 scala213source3") {
implicit val Scala213 = scala.meta.dialects.Scala213Source3
val code =
Expand All @@ -399,4 +419,25 @@ class DefnSuite extends ParseSuite {
runTestAssert[Stat](code, layout)(tree)
}

test("#3605 scala213source3") {
implicit val Scala213 = scala.meta.dialects.Scala213Source3
val code =
"""|new A {
| def b: C =
| ???
|
|}
|""".stripMargin
val layout =
"""|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(
tpl(
List(Init(pname("A"), anon, Nil)),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
)
)
runTestAssert[Stat](code, layout)(tree)
}

}
Expand Up @@ -3361,4 +3361,24 @@ class SignificantIndentationSuite extends BaseDottySuite {
runTestAssert[Stat](code, layout)(tree)
}

test("#3605 scala3") {
val code =
"""|new A {
| def b: C =
| ???
|
|}
|""".stripMargin
val layout =
"""|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(
tpl(
List(Init(pname("A"), anon, Nil)),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
)
)
runTestAssert[Stat](code, layout)(tree)
}

}

0 comments on commit 727c59c

Please sign in to comment.