diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala index 7a9a25a730..5d950493c7 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala @@ -41,6 +41,7 @@ object RedundantBraces extends Rewrite { def canRewriteWithParens(f: Term.Function, nested: Boolean = false): Boolean = !needParensAroundParams(f) && (getTermSingleStat(f.body) match { case Some(t: Term.Function) => canRewriteWithParens(t, true) + case Some(_: Defn) => false case x => nested || x.isDefined }) diff --git a/scalafmt-tests/src/test/resources/rewrite/RedundantBraces-ParenLambdas.stat b/scalafmt-tests/src/test/resources/rewrite/RedundantBraces-ParenLambdas.stat index a7f3512724..0abe01e979 100644 --- a/scalafmt-tests/src/test/resources/rewrite/RedundantBraces-ParenLambdas.stat +++ b/scalafmt-tests/src/test/resources/rewrite/RedundantBraces-ParenLambdas.stat @@ -192,9 +192,8 @@ object a { } } >>> -test does not parse object a { - childContext.onDone(_ => val _ = self.withChildren(_.remove(childContext))) + childContext.onDone { _ => val _ = self.withChildren(_.remove(childContext)) } } <<< #1756 def object a { @@ -203,9 +202,8 @@ object a { } } >>> -test does not parse object a { - childContext.onDone(_ => def a = self.withChildren(_.remove(childContext))) + childContext.onDone { _ => def a = self.withChildren(_.remove(childContext)) } } <<< #1756 type object a { @@ -214,7 +212,6 @@ object a { } } >>> -test does not parse object a { - childContext.onDone(_ => type a = Int) + childContext.onDone { _ => type a = Int } }