Skip to content

Commit

Permalink
FormatOps vertical multiline: one-param implicits
Browse files Browse the repository at this point in the history
Follow-on to #3469, where some single-param implicit groups were handled
incorrectly.

Earlier, if implicitParamListModifierForce=after was used, we would only
prohibit single-line formatting for multi-param groups, thus excluding
single-param groups.
  • Loading branch information
kitbellew committed Feb 20, 2023
1 parent 3bf5b8c commit 6168321
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1290,19 +1290,21 @@ class FormatOps(
Seq(slbSplit, noSplit.andPolicy(noSlbPolicy), nlSplit)
} else {
val rightIsImplicit = r.is[soft.ImplicitOrUsing]
val opensImplicit = rightIsImplicit &&
getImplicitParamList(ft.meta.rightOwner).exists(_.lengthCompare(1) > 0)
val nlOnly =
if (rightIsImplicit)
style.newlines.forceBeforeImplicitParamListModifier
else
style.verticalMultiline.newlineAfterOpenParen
val implicitParams =
if (!rightIsImplicit) Nil
else getImplicitParamList(ft.meta.rightOwner).getOrElse(Nil)
val noSlb = nlOnly || aboveArityThreshold || ft.hasBreak &&
!style.newlines.sourceIgnored && style.optIn.configStyleArguments ||
opensImplicit && style.newlines.forceAfterImplicitParamListModifier
implicitParams.nonEmpty &&
style.newlines.forceAfterImplicitParamListModifier
val nlMod = NewlineT(alt = if (nlOnly) None else Some(slbSplit.modExt))
val spaceImplicit =
opensImplicit && style.newlines.notBeforeImplicitParamListModifier
val spaceImplicit = !nlOnly && implicitParams.lengthCompare(1) > 0 &&
style.newlines.notBeforeImplicitParamListModifier
Seq(
// If we can fit all in one block, make it so
slbSplit.notIf(noSlb),
Expand Down
5 changes: 4 additions & 1 deletion scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4259,7 +4259,10 @@ object a:
def f[A](a: A, as: A*)[B](
b: B,
bs: B*
)[C](implicit c: C): B = ???
)[C](
implicit
c: C
): B = ???
class F(
a: A,
as: A*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4070,7 +4070,10 @@ object a:
def f[A](a: A, as: A*)[B](
b: B,
bs: B*
)[C](implicit c: C): B = ???
)[C](
implicit
c: C
): B = ???
class F(
a: A,
as: A*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4298,7 +4298,10 @@ object a:
def f[A](a: A, as: A*)[B](
b: B,
bs: B*
)[C](implicit c: C): B = ???
)[C](
implicit
c: C
): B = ???
class F(
a: A,
as: A*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4390,7 +4390,10 @@ object a:
def f[A](a: A, as: A*)[B](
b: B,
bs: B*
)[C](implicit c: C): B = ???
)[C](
implicit
c: C
): B = ???
class F(
a: A,
as: A*
Expand Down

0 comments on commit 6168321

Please sign in to comment.