From 9e63d443db38832f5a55036e1c3bccbaaffd2e64 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Mon, 18 Nov 2024 07:44:31 -0800 Subject: [PATCH] Router: handle Lit.Unit and empty ArgClause 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. --- .../src/main/scala/org/scalafmt/internal/Router.scala | 8 +++++++- .../shared/src/test/scala/org/scalafmt/FormatTests.scala | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 77ffd5831..0dab424b3 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -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 diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala index 285264e3c..ff96c1fd5 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -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 :'(