From 3f8108347253f015cb3ba9db5758bb245f82da18 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Mon, 3 Mar 2025 20:09:38 -0800 Subject: [PATCH] Splits: ensure break between `yield` and `case` --- .../src/main/scala/org/scalafmt/internal/Splits.scala | 6 ++++++ .../src/test/resources/scala3/OptionalBraces.stat | 8 ++------ .../test/resources/scala3/OptionalBraces_fold.stat | 8 +++----- .../test/resources/scala3/OptionalBraces_keep.stat | 9 ++------- .../test/resources/scala3/OptionalBraces_unfold.stat | 11 +++-------- .../src/test/scala/org/scalafmt/FormatTests.scala | 2 +- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Splits.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Splits.scala index 31f03bb8b..7a2df41a5 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Splits.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Splits.scala @@ -3381,6 +3381,12 @@ object SplitsAfterYield extends Splits { case t: Term.ForYield => Some(t.body) case _ => None }).fold(Seq.empty[Split]) { + case b: Term.PartialFunction + if dialect.allowSignificantIndentation && + nextNonComment(ft).right.is[T.KwCase] => + val split = Split(Newline, 0) + .withIndent(cfg.indent.getSignificant, getLast(b), ExpiresOn.After) + Seq(split) case b: Tree.Block if right.is[T.LeftBrace] && matchingOptRight(ft).exists(_.idx >= getLast(b).idx) => diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat index a415e98c1..5e186ca2b 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat @@ -8533,10 +8533,6 @@ for yield case Some(x) => foo >>> -test does not parse: [dialect scala3] illegal start of simple expression for foo <- Some(42) -yield case Some(x) => foo - ^ -====== full result: ====== -for foo <- Some(42) -yield case Some(x) => foo +yield + case Some(x) => foo diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat index 2c97df831..bd57bebf0 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat @@ -8196,8 +8196,6 @@ for yield case Some(x) => foo >>> -test does not parse: [dialect scala3] illegal start of simple expression -for foo <- Some(42) yield case Some(x) => foo - ^ -====== full result: ====== -for foo <- Some(42) yield case Some(x) => foo +for foo <- Some(42) +yield + case Some(x) => foo diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat index 656c61c14..529b5cb52 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat @@ -8555,12 +8555,7 @@ for yield case Some(x) => foo >>> -test does not parse: [dialect scala3] illegal start of simple expression for foo <- Some(42) -yield case Some(x) => foo - ^ -====== full result: ====== -for - foo <- Some(42) -yield case Some(x) => foo +yield + case Some(x) => foo diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat index 84ae37574..a4409a44e 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -8883,12 +8883,7 @@ for yield case Some(x) => foo >>> -test does not parse: [dialect scala3] illegal start of simple expression for foo <- Some(42) -yield case Some(x) => - ^ - foo -====== full result: ====== -for foo <- Some(42) -yield case Some(x) => - foo +yield + case Some(x) => + foo diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala index b389e5580..127f22a24 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -148,7 +148,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, 2536504, "total explored") + assertEquals(explored, 2536664, "total explored") // TODO(olafur) don't block printing out test results. TestPlatformCompat.executeAndWait(PlatformFileOps.writeFile( FileOps.getPath("target", "index.html"),