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 20, 2023
1 parent 6168321 commit 8951c58
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,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) {}
}
33 changes: 22 additions & 11 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 @@ -3995,7 +3996,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 @@ -4024,14 +4026,16 @@ object a:
c: C
): B = ???
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 @@ -4098,14 +4102,16 @@ object a:
c: C
): B = ???
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 @@ -4148,7 +4154,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 @@ -4234,7 +4241,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 @@ -4426,7 +4434,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 @@ -4439,7 +4448,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 @@ -4490,6 +4500,7 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
33 changes: 22 additions & 11 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 @@ -3806,7 +3807,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 @@ -3835,14 +3837,16 @@ object a:
c: C
): B = ???
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 @@ -3909,14 +3913,16 @@ object a:
c: C
): B = ???
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 @@ -3959,7 +3965,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 @@ -4045,7 +4052,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 @@ -4237,7 +4245,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 @@ -4250,7 +4259,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 @@ -4301,6 +4311,7 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
33 changes: 22 additions & 11 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 @@ -4034,7 +4035,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 @@ -4063,14 +4065,16 @@ object a:
c: C
): B = ???
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 @@ -4137,14 +4141,16 @@ object a:
c: C
): B = ???
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 @@ -4187,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, implicitParamListModifierPrefer = before
Expand Down Expand Up @@ -4273,7 +4280,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 @@ -4468,7 +4476,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 @@ -4481,7 +4490,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 @@ -4532,6 +4542,7 @@ object a:
as: A*
)(b: B,
bs: B*
)(implicit c: C,
)(implicit
c: C,
d: D,
implicit e: E) {}
Loading

0 comments on commit 8951c58

Please sign in to comment.