diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index 21ff869697..fef1688937 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -751,10 +751,19 @@ class FormatOps(val tree: Tree, val initStyle: ScalafmtConfig) { leftTok2tok(matching(token)) match { case FormatToken(RightParenOrBracket(), l @ LeftParen(), _) => loop(l) - // This case only applies to classes - case f @ FormatToken(RightBracket(), mod, _) if mod.is[Modifier] => - loop(next(f).right) - case FormatToken(r @ RightParenOrBracket(), _, _) => Some(r) + case f @ FormatToken(left @ RightParenOrBracket(), right, _) => + right match { + case Modifier() => + // This case only applies to classes + next(f).right match { + case x @ (_: Token.LeftParen | _: Token.LeftBracket) => + loop(x) + case _ => + Some(left) + } + case _ => + Some(left) + } case _ => None } } diff --git a/scalafmt-tests/src/test/resources/vertical-multiline/verticalMultiline.stat b/scalafmt-tests/src/test/resources/vertical-multiline/verticalMultiline.stat index d5fdbe173d..ee8a3ddf08 100644 --- a/scalafmt-tests/src/test/resources/vertical-multiline/verticalMultiline.stat +++ b/scalafmt-tests/src/test/resources/vertical-multiline/verticalMultiline.stat @@ -269,3 +269,13 @@ class SomeVeryLongName[ SomeOtherTypeName, YetAnotherType] extends Something +<<< #1203 +object Recorder { + sealed abstract class Ast[A] + final case class Record() +} +>>> +object Recorder { + sealed abstract class Ast[A] + final case class Record() +}