From 0e3a6ffc1aee52e9cbec447c9d9d96bf370ec9ad Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 5 Oct 2024 22:24:56 -0700 Subject: [PATCH] FormatWriter: fix rare but possible bug --- .../src/main/scala/org/scalafmt/internal/FormatWriter.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala index 4d073de42..bfe47706b 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatWriter.scala @@ -1171,7 +1171,9 @@ class FormatWriter(formatOps: FormatOps) { val ft = floc.formatToken idx += 1 columnShift += floc.shift - if (floc.hasBreakAfter || ft.leftHasNewline) floc + if ( + floc.hasBreakAfter || ft.leftHasNewline || idx >= locations.length + ) floc else { getAlignNonSlcOwner(ft, locations(idx)).foreach { nonSlcOwner => val (container, depth) =