Skip to content

Commit

Permalink
RedundantParens: enforce infixSide more precisely
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 22, 2024
1 parent 006ef7a commit 98fd0a9
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ class RedundantParens(implicit val ftoks: FormatTokens)
(style.dialect.allowTryWithAnyExpr || p.expr.ne(t)) &&
canRewriteBody(t)
case p: Term.ArgClause => p.parent.exists {
case pia: Member.Infix => !infixNeedsParens(pia, t) &&
okToReplaceInfix(pia, t)
case pia: Member.Infix => okToReplaceInfix(pia, t)
case _ => true
}
case pia: Member.Infix if !infixNeedsParens(pia, t) =>
okToReplaceInfix(pia, t)
case pia: Member.Infix => okToReplaceInfix(pia, t)
case p: Tree.WithDeclTpe if p.decltpe eq t => true
case p: Tree.WithDeclTpeOpt if p.decltpe.contains(t) => true
case _ => okToReplaceOther(t)
Expand All @@ -152,9 +150,7 @@ class RedundantParens(implicit val ftoks: FormatTokens)
case _: Lit.Unit | _: Member.Tuple => false
case _: Term.SelectPostfix => false
case _ => t.parent.exists {
case pia: Member.Infix =>
val keep = infixNeedsParens(pia, arg)
if (keep) okToReplaceOther(arg) else okToReplaceInfix(pia, arg)
case pia: Member.Infix => okToReplaceInfix(pia, arg)
case _ => false
}
}
Expand All @@ -180,11 +176,10 @@ class RedundantParens(implicit val ftoks: FormatTokens)
private def okToReplaceInfix(pia: Member.Infix, t: Tree)(implicit
style: ScalafmtConfig,
): Boolean = t match {
case _: Term.AnonymousFunction | _: Term.SelectPostfix => false
case _ if infixNeedsParens(pia, t) => false
case tia: Member.Infix => okToReplaceInfix(pia, tia)
case _: Lit | _: Name | _: Term.Interpolate => true
case _: Term.PartialFunction => true
case _: Term.AnonymousFunction => false
case _: Term.SelectPostfix => false
case _ => style.rewrite.redundantParens.infixSide.isDefined
}

Expand Down

0 comments on commit 98fd0a9

Please sign in to comment.