diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 366ed459a6a0..4097ed750011 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -280,6 +280,12 @@ object Parsers { syntaxError(msg, offset) skip(stopAtComma = true) + def syntaxErrorOrIncomplete(msg: Message, span: Span): Unit = + if (in.token == EOF) incompleteInputError(msg) + else + syntaxError(msg, span) + skip(stopAtComma = true) + /** Consume one token of the specified type, or * signal an error if it is not there. * @@ -2003,7 +2009,7 @@ object Parsers { handler match { case Block(Nil, EmptyTree) => assert(handlerStart != -1) - syntaxError( + syntaxErrorOrIncomplete( EmptyCatchBlock(body), Span(handlerStart, endOffset(handler)) ) diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index c02552aac83c..69b3df423c5b 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -300,4 +300,14 @@ class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose"): run("val a = 42") assert(storedOutput().trim().endsWith("val a: Int = 42")) } + + @Test def `i4393-incomplete-catch`: Unit = contextually { + assert(ParseResult.isIncomplete("""|try { + | ??? + |} catch""".stripMargin)) + assert(ParseResult.isIncomplete("""|try { + | ??? + |} catch {""".stripMargin)) + } + end ReplVerboseTests