Skip to content

Commit c80bebf

Browse files
committed
Splits: ensure break between yield and case
1 parent a6d8350 commit c80bebf

File tree

6 files changed

+17
-27
lines changed

6 files changed

+17
-27
lines changed

scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Splits.scala

+6
Original file line numberDiff line numberDiff line change
@@ -3381,6 +3381,12 @@ object SplitsAfterYield extends Splits {
33813381
case t: Term.ForYield => Some(t.body)
33823382
case _ => None
33833383
}).fold(Seq.empty[Split]) {
3384+
case b: Term.PartialFunction
3385+
if dialect.allowSignificantIndentation &&
3386+
nextNonComment(ft).right.is[T.KwCase] =>
3387+
val split = Split(Newline, 0)
3388+
.withIndent(cfg.indent.getSignificant, getLast(b), ExpiresOn.After)
3389+
Seq(split)
33843390
case b: Tree.Block
33853391
if right.is[T.LeftBrace] &&
33863392
matchingOptRight(ft).exists(_.idx >= getLast(b).idx) =>

scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat

+2-6
Original file line numberDiff line numberDiff line change
@@ -8533,10 +8533,6 @@ for
85338533
yield
85348534
case Some(x) => foo
85358535
>>>
8536-
test does not parse: [dialect scala3] illegal start of simple expression
85378536
for foo <- Some(42)
8538-
yield case Some(x) => foo
8539-
^
8540-
====== full result: ======
8541-
for foo <- Some(42)
8542-
yield case Some(x) => foo
8537+
yield
8538+
case Some(x) => foo

scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat

+3-5
Original file line numberDiff line numberDiff line change
@@ -8196,8 +8196,6 @@ for
81968196
yield
81978197
case Some(x) => foo
81988198
>>>
8199-
test does not parse: [dialect scala3] illegal start of simple expression
8200-
for foo <- Some(42) yield case Some(x) => foo
8201-
^
8202-
====== full result: ======
8203-
for foo <- Some(42) yield case Some(x) => foo
8199+
for foo <- Some(42)
8200+
yield
8201+
case Some(x) => foo

scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat

+2-7
Original file line numberDiff line numberDiff line change
@@ -8555,12 +8555,7 @@ for
85558555
yield
85568556
case Some(x) => foo
85578557
>>>
8558-
test does not parse: [dialect scala3] illegal start of simple expression
85598558
for
85608559
foo <- Some(42)
8561-
yield case Some(x) => foo
8562-
^
8563-
====== full result: ======
8564-
for
8565-
foo <- Some(42)
8566-
yield case Some(x) => foo
8560+
yield
8561+
case Some(x) => foo

scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat

+3-8
Original file line numberDiff line numberDiff line change
@@ -8883,12 +8883,7 @@ for
88838883
yield
88848884
case Some(x) => foo
88858885
>>>
8886-
test does not parse: [dialect scala3] illegal start of simple expression
88878886
for foo <- Some(42)
8888-
yield case Some(x) =>
8889-
^
8890-
foo
8891-
====== full result: ======
8892-
for foo <- Some(42)
8893-
yield case Some(x) =>
8894-
foo
8887+
yield
8888+
case Some(x) =>
8889+
foo

scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
148148
val explored = Debug.explored.get()
149149
logger.debug(s"Total explored: $explored")
150150
if (!onlyUnit && !onlyManual)
151-
assertEquals(explored, 2537756, "total explored")
151+
assertEquals(explored, 2537916, "total explored")
152152
// TODO(olafur) don't block printing out test results.
153153
TestPlatformCompat.executeAndWait(PlatformFileOps.writeFile(
154154
FileOps.getPath("target", "index.html"),

0 commit comments

Comments
 (0)