diff --git a/compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala b/compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala index 06a787978a0b..551d4f8d809e 100644 --- a/compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala +++ b/compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala @@ -117,7 +117,8 @@ trait BytecodeWriters { catch case ex: ClosedByInterruptException => try outfile.delete() // don't leave an empty or half-written classfile around after an interrupt - catch case _: Throwable => + catch + case _: Throwable => throw ex finally outstream.close() report.informProgress("wrote '" + label + "' to " + outfile) diff --git a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala index 6a763a9c0744..f00c54e584f9 100644 --- a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala +++ b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala @@ -275,7 +275,8 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim catch case ex: ClosedByInterruptException => try outTastyFile.delete() // don't leave an empty or half-written tastyfile around after an interrupt - catch case _: Throwable => + catch + case _: Throwable => throw ex finally outstream.close() diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 7a5620be0415..803db0ec6367 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2620,7 +2620,14 @@ object Parsers { (pattern(), guard()) } CaseDef(pat, grd, atSpan(accept(ARROW)) { - if exprOnly then expr() else block() + if exprOnly then + if in.indentSyntax && in.isAfterLineEnd && in.token != INDENT then + warning(i"""Misleading indentation: this expression forms part of the preceding catch case. + |If this is intended, it should be indented for clarity. + |Otherwise, if the handler is intended to be empty, use a multi-line catch with + |an indented case.""") + expr() + else block() }) } diff --git a/compiler/test/dotty/tools/repl/ShadowingTests.scala b/compiler/test/dotty/tools/repl/ShadowingTests.scala index 564ac6258633..1ba58a4babff 100644 --- a/compiler/test/dotty/tools/repl/ShadowingTests.scala +++ b/compiler/test/dotty/tools/repl/ShadowingTests.scala @@ -33,7 +33,7 @@ object ShadowingTests: val subdir = dir.resolve(name) try Files.createDirectory(subdir) catch case _: java.nio.file.FileAlreadyExistsException => - assert(Files.isDirectory(subdir), s"failed to create shadowed subdirectory $subdir") + assert(Files.isDirectory(subdir), s"failed to create shadowed subdirectory $subdir") subdir // The directory on the classpath containing artifacts to be shadowed diff --git a/tests/neg-custom-args/fatal-warnings/i14721.scala b/tests/neg-custom-args/fatal-warnings/i14721.scala new file mode 100644 index 000000000000..6e884cad22d7 --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i14721.scala @@ -0,0 +1,8 @@ + +class C: + def op: Unit = println("op") + def handler: Unit = println("handler") + def test: Unit = + try op + catch case _: NullPointerException => + handler // error