Skip to content

Commit cf9525c

Browse files
authored
Merge pull request #14519 from ckipp01/incompleteCatch
fix(parser): make empty catch an incomplete.
2 parents f19b850 + cd143da commit cf9525c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ object Parsers {
280280
syntaxError(msg, offset)
281281
skip(stopAtComma = true)
282282

283+
def syntaxErrorOrIncomplete(msg: Message, span: Span): Unit =
284+
if (in.token == EOF) incompleteInputError(msg)
285+
else
286+
syntaxError(msg, span)
287+
skip(stopAtComma = true)
288+
283289
/** Consume one token of the specified type, or
284290
* signal an error if it is not there.
285291
*
@@ -2003,7 +2009,7 @@ object Parsers {
20032009
handler match {
20042010
case Block(Nil, EmptyTree) =>
20052011
assert(handlerStart != -1)
2006-
syntaxError(
2012+
syntaxErrorOrIncomplete(
20072013
EmptyCatchBlock(body),
20082014
Span(handlerStart, endOffset(handler))
20092015
)

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

+10
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,14 @@ class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose"):
300300
run("val a = 42")
301301
assert(storedOutput().trim().endsWith("val a: Int = 42"))
302302
}
303+
304+
@Test def `i4393-incomplete-catch`: Unit = contextually {
305+
assert(ParseResult.isIncomplete("""|try {
306+
| ???
307+
|} catch""".stripMargin))
308+
assert(ParseResult.isIncomplete("""|try {
309+
| ???
310+
|} catch {""".stripMargin))
311+
}
312+
303313
end ReplVerboseTests

0 commit comments

Comments
 (0)