From f23ff3abba8663a0e7f64f79b556efd36cc86a83 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 29 Sep 2016 17:10:45 +0200 Subject: Improve positions for MemberDefs using `namePos` --- src/dotty/tools/dotc/parsing/Parsers.scala | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/dotty/tools/dotc/parsing/Parsers.scala') 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) -- cgit v1.2.3