Skip to content

Commit

Permalink
Router: handle Lit.Unit and empty ArgClause
Browse files Browse the repository at this point in the history
Depending on the dialect, `a + ()` might parse the argument as an empty
ArgClause or a single-arg Lit.Unit, which might lead to differences in
formatting rules considered.
  • Loading branch information
kitbellew committed Nov 18, 2024
1 parent 8278310 commit dc2b384
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,16 @@ class Router(formatOps: FormatOps) {
)
}

case FT(T.LeftParen(), T.RightParen(), _) =>
case FT(_: T.LeftParen, _: T.RightParen, _) =>
val noNL = style.newlines.sourceIgnored || noBreak()
Seq(Split(NoSplit.orNL(noNL), 0))

case FT(_: T.LeftParen, _: T.Comment, _) if (leftOwner match {
case _: Lit.Unit => true
case t: Member.ArgClause => t.values.isEmpty
case _ => false
}) && !hasBreakBeforeNonComment(ft) => Seq(Split(Space, 0))

case FT(open @ LeftParenOrBracket(), right, _) if {
if (isArgClauseSite(leftOwner)) style.binPack.callSiteFor(open) ==
BinPack.Site.Never
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
val explored = Debug.explored.get()
logger.debug(s"Total explored: $explored")
if (!onlyUnit && !onlyManual)
assertEquals(explored, 1082952, "total explored")
assertEquals(explored, 1082944, "total explored")
val results = debugResults.result()
// TODO(olafur) don't block printing out test results.
// I don't want to deal with scalaz's Tasks :'(
Expand Down

0 comments on commit dc2b384

Please sign in to comment.