diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index e499568fd5..2c09317bb5 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -1491,14 +1491,14 @@ class FormatOps( case SplitDefnIntoParts(_, _, _, paramss) => findArgsFor(ft.left, paramss) // make sure there's no other param with implicit - .filter(!_.exists(TreeOps.hasExplicitImplicit)) + .filter(_.forall(TreeOps.noExplicitImplicit)) case _ => None } /** Works for `using` as well */ def opensImplicitParamList(ft: FormatToken, args: Seq[Tree]): Boolean = ft.right.is[T.KwImplicit] && args.forall { - case t: Term.Param => !hasExplicitImplicit(t) + case t: Term.Param => noExplicitImplicit(t) case _ => true } || ft.right.is[soft.KwUsing] diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/SortModifiers.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/SortModifiers.scala index 10da8acdb7..c7ec862be5 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/SortModifiers.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/SortModifiers.scala @@ -39,7 +39,7 @@ class SortModifiers(implicit ctx: RewriteCtx) extends RewriteSession { val start = p.pos.start sortMods(p.mods.filterNot { m => m.is[Mod.ValParam] || m.is[Mod.VarParam] || - TreeOps.isHiddenImplicit(start)(m) + TreeOps.noExplicitImplicit(start, false)(m) }) case _ => } diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/util/TreeOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/util/TreeOps.scala index 17d75a5d55..87541eaa2c 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/util/TreeOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/util/TreeOps.scala @@ -697,25 +697,21 @@ object TreeOps { * `val i1`, and `var i2` positions do not include their ``Mod.Implicit``. * `var i3` has a ``Mod.Implicit`` which is included. */ - def isExplicitImplicit(m: Mod.Implicit, ownerStart: Int): Boolean = { + def noExplicitImplicit(m: Mod.Implicit, ownerStart: Int): Boolean = { val modPos = m.pos val modStart = modPos.start - modStart >= ownerStart && modPos.end > modStart + modStart < ownerStart || modPos.end <= modStart } - def isHiddenImplicit(ownerStart: Int)(m: Mod): Boolean = m match { - case m: Mod.Implicit => !isExplicitImplicit(m, ownerStart) - case _ => false - } - - def isExplicitImplicit(ownerStart: Int)(m: Mod): Boolean = m match { - case m: Mod.Implicit => isExplicitImplicit(m, ownerStart) - case _ => false - } + def noExplicitImplicit(ownerStart: Int, orElse: Boolean)(m: Mod): Boolean = + m match { + case m: Mod.Implicit => noExplicitImplicit(m, ownerStart) + case _ => orElse + } - def hasExplicitImplicit(param: Term.Param): Boolean = { + def noExplicitImplicit(param: Term.Param): Boolean = { val pStart = param.pos.start - param.mods.exists(isExplicitImplicit(pStart)) + param.mods.forall(noExplicitImplicit(pStart, true)) } def shouldNotDangleAtDefnSite(