Skip to content

Commit

Permalink
FormatOps: bugfix, check else for opening brace
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Aug 17, 2022
1 parent 135dfc4 commit 7229211
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2529,7 +2529,7 @@ class FormatOps(
@tailrec
private def isElsePWithOptionalBraces(tree: Term.If): Boolean = {
val elsep = tree.elsep
!tokenBefore(elsep).left.is[T.LeftBrace] && (elsep match {
!tokens.getHead(elsep).left.is[T.LeftBrace] && (elsep match {
case t: Term.If =>
isThenPWithOptionalBraces(t) ||
!ifWithoutElse(t) && isElsePWithOptionalBraces(t)
Expand Down
3 changes: 2 additions & 1 deletion scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -3547,7 +3547,8 @@ class Foo() {
}

def notOK: Boolean =
if (1 == 1) true
if (1 == 1)
true
else {
println("Some code")
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3530,7 +3530,7 @@ class Foo() {

def notOK: Boolean =
if (1 == 1)
true
true
else {
println("Some code")
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3655,7 +3655,7 @@ class Foo() {

def notOK: Boolean =
if (1 == 1)
true
true
else {
println("Some code")
false
Expand Down

0 comments on commit 7229211

Please sign in to comment.