From 4aa44f5c8a499759e080013b824bece5d1a8d102 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 12 Jun 2020 10:19:23 +0200 Subject: [PATCH] Fix #9168: Use `()` for `finally` with empty expression --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 7 ++++++- tests/neg-custom-args/fatal-warnings/i9168.scala | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/neg-custom-args/fatal-warnings/i9168.scala 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