Skip to content

Commit

Permalink
TreeOps: a braceless match is like fewer-braces
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 21, 2024
1 parent 8437d83 commit a2bfb51
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class FormatOps(
val mod =
if (ft.noBreak || !okToBreak) spaceMod
else Newline2x(isFullInfixEnclosed && ft.hasBlankLine)
val split = Split(mod, 0)
def split(implicit fl: FileLine) = Split(mod, 0)
if (isBeforeOp && isFewerBracesRhs(app.arg)) Seq(split)
else Seq(InfixSplits.withNLIndent(split, app, fullInfix))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object TreeSyntacticGroup {
case _: Term.Xml => g.Term.SimpleExpr1
case _: Term.Apply => g.Term.SimpleExpr1
case _: Term.ApplyType => g.Term.SimpleExpr1
case _: Term.SelectMatch => g.Term.SimpleExpr1
case t: Term.ApplyInfix => g.Term.InfixExpr(t.op.value)
case t: Term.ApplyUnary => g.Term.PrefixExpr(t.op.value)
case _: Term.Assign => g.Term.Expr1
Expand All @@ -34,7 +35,6 @@ object TreeSyntacticGroup {
case _: Term.TryClause => g.Term.Expr1
case _: Term.FunctionTerm => g.Term.Expr
case _: Term.PolyFunction => g.Term.Expr
case _: Term.SelectMatch => g.Term.SimpleExpr
case _: Term.PartialFunction => g.Term.SimpleExpr
case _: Term.While => g.Term.Expr1
case _: Term.Do => g.Term.Expr1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ object TreeOps {
case t: Term.ApplyInfix => isFewerBracesLhs(t.argClause)
case _ => false
}
case t: Tree.WithCasesBlock => !ftoks.isEnclosedInMatching(t.casesBlock)
case _ => false
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,18 @@ object a {
)
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
case false => false
- + e
+ + e
val b = c + (d match
object a {
val b = c + d.match
case true => true
case false => false
val b = c + d.match
case true => true
case false => false
+ e
val b = c + (d match
case true => true
case false => false)
}
<<< #2194 6 match with parens, dot and no braces, !infixSide
runner.dialect = scala3
rewrite.redundantParens.infixSide = null
Expand Down

0 comments on commit a2bfb51

Please sign in to comment.