Skip to content

Fix printing catch clause #4694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,12 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
this += "try "
printTree(body)
if (cases.nonEmpty) {
this += " catch "
printCases(cases, lineBreak())
this += " catch {"
indented {
this += lineBreak()
printCases(cases, lineBreak())
}
this += lineBreak() += "}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worthy to create another verb like braced which could be used in several places to simplify the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea. I will add it in another PR.

}
finallyOpt match {
case Some(t) =>
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/simpleTry.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** Decompiled from out/posTestFromTasty/pos/simpleTry/Foo.class */
class Foo() {
try 3 catch {
case e: scala.Throwable =>
4
} finally scala.Predef.println(6)
}
7 changes: 7 additions & 0 deletions tests/pos/simpleTry.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

class Foo {
try 3
catch {
case e: Throwable => 4
} finally println(6)
}