Skip to content

Commit

Permalink
Merge pull request #14519 from ckipp01/incompleteCatch
Browse files Browse the repository at this point in the history
fix(parser): make empty catch an incomplete.
  • Loading branch information
odersky committed Feb 21, 2022
2 parents f19b850 + cd143da commit cf9525c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Expand Up @@ -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.
*
Expand Down Expand Up @@ -2003,7 +2009,7 @@ object Parsers {
handler match {
case Block(Nil, EmptyTree) =>
assert(handlerStart != -1)
syntaxError(
syntaxErrorOrIncomplete(
EmptyCatchBlock(body),
Span(handlerStart, endOffset(handler))
)
Expand Down
10 changes: 10 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Expand Up @@ -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

0 comments on commit cf9525c

Please sign in to comment.