Skip to content

Commit

Permalink
TreeOps: fix handling implicit group keyword
Browse files Browse the repository at this point in the history
Earlier, we would only handle the first `implicit` differently if none
of the params have an explicit `implicit` keyword.

In reality, we should relax the check and do this if not all params have
an explicit keyword. The idea being, if they all do, then the initial
one belongs to the first parameter rather than the group.
  • Loading branch information
kitbellew committed Feb 18, 2023
1 parent b7190bc commit 124b75e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,9 @@ object TreeOps {
def getImplicitParamList(kwOwner: Tree): Option[Seq[Tree]] =
kwOwner.parent match {
case Some(Term.ArgClause(v, Some(`kwOwner`))) => Some(v)
case Some(Term.ParamClause(v, Some(`kwOwner`))) if (kwOwner match {
case _: Mod.Implicit => v.forall(noExplicitImplicit)
case _ => true
}) =>
case Some(Term.ParamClause(v @ head :: rest, Some(`kwOwner`)))
if !kwOwner.is[Mod.Implicit] || rest.isEmpty ||
!noExplicitImplicit(head) || rest.exists(noExplicitImplicit) =>
Some(v)
case _ => None
}
Expand Down
15 changes: 10 additions & 5 deletions scalafmt-tests/src/test/resources/default/Class.stat
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ object a {
implicit c: C,
implicit d: D) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E) {}
}
Expand All @@ -621,12 +622,14 @@ object a {
>>>
object a {
class F(a: A, as: A*)(b: B, bs: B*)(
implicit implicit c: C) {}
implicit
implicit c: C) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit d: D) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E) {}
}
Expand Down Expand Up @@ -663,12 +666,14 @@ object a {
>>>
object a {
class F(a: A, as: A*)(b: B, bs: B*)(
implicit implicit c: C) {}
implicit
implicit c: C) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit d: D) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E) {}
}
18 changes: 12 additions & 6 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -3931,7 +3931,8 @@ object a:
implicit d: D
) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E
) {}
Expand Down Expand Up @@ -3974,7 +3975,8 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
<<< interleaved, vertical multiline, implicitParamListModifierPrefer = before
Expand Down Expand Up @@ -4060,7 +4062,8 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
<<< interleaved, vertical multiline, implicitParamListModifierForce = [after]
Expand Down Expand Up @@ -4249,7 +4252,8 @@ object a:
a: A,
as: A*
)(b: B, bs: B*)(
implicit implicit c: C
implicit
implicit c: C
) {}
class F(
a: A,
Expand All @@ -4262,7 +4266,8 @@ object a:
a: A,
as: A*
)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E
) {}
Expand Down Expand Up @@ -4313,6 +4318,7 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
18 changes: 12 additions & 6 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -3742,7 +3742,8 @@ object a:
implicit d: D
) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E
) {}
Expand Down Expand Up @@ -3785,7 +3786,8 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
<<< interleaved, vertical multiline, implicitParamListModifierPrefer = before
Expand Down Expand Up @@ -3871,7 +3873,8 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
<<< interleaved, vertical multiline, implicitParamListModifierForce = [after]
Expand Down Expand Up @@ -4060,7 +4063,8 @@ object a:
a: A,
as: A*
)(b: B, bs: B*)(
implicit implicit c: C
implicit
implicit c: C
) {}
class F(
a: A,
Expand All @@ -4073,7 +4077,8 @@ object a:
a: A,
as: A*
)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E
) {}
Expand Down Expand Up @@ -4124,6 +4129,7 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
18 changes: 12 additions & 6 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -3970,7 +3970,8 @@ object a:
implicit d: D
) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E
) {}
Expand Down Expand Up @@ -4013,7 +4014,8 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
<<< interleaved, vertical multiline, implicitParamListModifierPrefer = before
Expand Down Expand Up @@ -4099,7 +4101,8 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
<<< interleaved, vertical multiline, implicitParamListModifierForce = [after]
Expand Down Expand Up @@ -4291,7 +4294,8 @@ object a:
a: A,
as: A*
)(b: B, bs: B*)(
implicit implicit c: C
implicit
implicit c: C
) {}
class F(
a: A,
Expand All @@ -4304,7 +4308,8 @@ object a:
a: A,
as: A*
)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E
) {}
Expand Down Expand Up @@ -4355,6 +4360,7 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4062,7 +4062,8 @@ object a:
implicit d: D
) {}
class F(a: A, as: A*)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E
) {}
Expand Down Expand Up @@ -4105,7 +4106,8 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
<<< interleaved, vertical multiline, implicitParamListModifierPrefer = before
Expand Down Expand Up @@ -4191,7 +4193,8 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
<<< interleaved, vertical multiline, implicitParamListModifierForce = [after]
Expand Down Expand Up @@ -4380,7 +4383,8 @@ object a:
a: A,
as: A*
)(b: B, bs: B*)(
implicit implicit c: C
implicit
implicit c: C
) {}
class F(
a: A,
Expand All @@ -4393,7 +4397,8 @@ object a:
a: A,
as: A*
)(b: B, bs: B*)(
implicit c: C,
implicit
c: C,
d: D,
implicit e: E
) {}
Expand Down Expand Up @@ -4444,6 +4449,7 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ object a {
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
}
Expand Down

0 comments on commit 124b75e

Please sign in to comment.