Skip to content

Commit 6812241

Browse files
Merge pull request #4694 from dotty-staging/fix-catch-clause-printing
Fix printing `catch` clause
2 parents 998de24 + a3d332b commit 6812241

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,12 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
373373
this += "try "
374374
printTree(body)
375375
if (cases.nonEmpty) {
376-
this += " catch "
377-
printCases(cases, lineBreak())
376+
this += " catch {"
377+
indented {
378+
this += lineBreak()
379+
printCases(cases, lineBreak())
380+
}
381+
this += lineBreak() += "}"
378382
}
379383
finallyOpt match {
380384
case Some(t) =>

tests/pos/simpleTry.decompiled

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** Decompiled from out/posTestFromTasty/pos/simpleTry/Foo.class */
2+
class Foo() {
3+
try 3 catch {
4+
case e: scala.Throwable =>
5+
4
6+
} finally scala.Predef.println(6)
7+
}

tests/pos/simpleTry.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
class Foo {
3+
try 3
4+
catch {
5+
case e: Throwable => 4
6+
} finally println(6)
7+
}

0 commit comments

Comments
 (0)