Skip to content

Commit

Permalink
ScannerTokens: yet another leading infix fix
Browse files Browse the repository at this point in the history
- first, match HSpace instead of Whitespace, to exclude LFLF
- second, on double EOL, return No instead of InvalidArg (which is used
  to indicate incorrectly indented infix arguments).
  • Loading branch information
kitbellew committed Mar 3, 2024
1 parent d8f42a9 commit 3310146
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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 @@ -428,11 +428,16 @@ class DefnSuite extends ParseSuite {
|
|}
|""".stripMargin
val error =
"""|<input>:2: error: illegal start of simple expression
| def b: C =
| ^""".stripMargin
runTestError[Stat](code, error)
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 3310146

Please sign in to comment.