Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeOps: a braceless match is like fewer-braces #4577

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,4 +1,5 @@
rewrite.rules = [RedundantParens]
rewrite.redundantParens.infixSide = some
<<< basic
object a {
def c(b: List[Int]): List[Int] =
Expand Down Expand Up @@ -553,6 +554,35 @@ object a {
)
}
>>>
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
===
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
)
}
>>>
object a {
val b = c + (d.match
case true => true
Expand Down Expand Up @@ -940,6 +970,22 @@ object a {
(new foo(bar).baz) * qux
}
>>>
object a {
foo * new bar
foo * new bar(baz).qux
new foo * bar
new foo(bar).baz * qux
}
<<< infix with new, !infixSide
rewrite.redundantParens.infixSide = null
===
object a {
foo * (new bar)
foo * (new bar(baz).qux)
(new foo) * bar
(new foo(bar).baz) * qux
}
>>>
object a {
foo * (new bar)
foo * (new bar(baz).qux)
Expand Down Expand Up @@ -987,6 +1033,8 @@ object a {
new foo(bar: baz)
}
<<< infix expressions with infixSide = null
rewrite.redundantParens.infixSide = null
===
object a {
// null+
foo & (0) // literal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
val explored = Debug.explored.get()
logger.debug(s"Total explored: $explored")
if (!onlyUnit && !onlyManual)
assertEquals(explored, 1084572, "total explored")
assertEquals(explored, 1084768, "total explored")
val results = debugResults.result()
// TODO(olafur) don't block printing out test results.
// I don't want to deal with scalaz's Tasks :'(
Expand Down