aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/parsing/Parsers.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/parsing/Parsers.scala')
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index 620cc1273..6d40107a8 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -215,6 +215,9 @@ object Parsers {
}
}
+ def warning(msg: Message, sourcePos: SourcePosition) =
+ ctx.warning(msg, sourcePos)
+
def warning(msg: Message, offset: Int = in.offset) =
ctx.warning(msg, source atPos Position(offset))
@@ -1006,6 +1009,7 @@ object Parsers {
DoWhile(body, cond)
}
case TRY =>
+ val tryOffset = in.offset
atPos(in.skipToken()) {
val body = expr()
val handler =
@@ -1014,16 +1018,26 @@ object Parsers {
expr()
} else EmptyTree
+ // A block ends before RBRACE, if next token is RBRACE, simply add 1
+ def realEnd(pos: Position) =
+ if (in.token == RBRACE) pos.end + 1
+ else pos.end
+
handler match {
- case Block(Nil, EmptyTree) =>
- syntaxError(new EmptyCatchBlock(body), handler.pos)
+ case Block(Nil, EmptyTree) => syntaxError(
+ new EmptyCatchBlock(body),
+ Position(tryOffset, realEnd(handler.pos))
+ )
case _ =>
}
val finalizer =
if (in.token == FINALLY) { accept(FINALLY); expr() }
else {
- if (handler.isEmpty) warning(EmptyCatchAndFinallyBlock(body))
+ if (handler.isEmpty) warning(
+ EmptyCatchAndFinallyBlock(body),
+ source atPos Position(tryOffset, realEnd(body.pos))
+ )
EmptyTree
}
ParsedTry(body, handler, finalizer)