diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 38294638948f..e12d3a7fb8e3 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2004,7 +2004,12 @@ object Parsers { } val finalizer = - if (in.token == FINALLY) { in.nextToken(); subExpr() } + if (in.token == FINALLY) { + in.nextToken(); + val expr = subExpr() + if expr.span.exists then expr + else Literal(Constant(())) // finally without an expression + } else { if (handler.isEmpty) warning( EmptyCatchAndFinallyBlock(body), diff --git a/tests/neg-custom-args/fatal-warnings/i9168.scala b/tests/neg-custom-args/fatal-warnings/i9168.scala new file mode 100644 index 000000000000..59263239f378 --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i9168.scala @@ -0,0 +1 @@ +def g: Int = try 42 finally ; // error