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: yet another leading infix fix #3606

Merged
merged 2 commits into from Mar 6, 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 @@ -969,8 +969,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 @@ -981,7 +981,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)
}

}