Skip to content

Commit 29d19ba

Browse files
committed
Correct line extraction from SourcePosition
1 parent 41d6429 commit 29d19ba

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,22 +1012,20 @@ object Parsers {
10121012
val tryOffset = in.offset
10131013
atPos(in.skipToken()) {
10141014
val body = expr()
1015-
val handler =
1015+
val (handler, handlerStart) =
10161016
if (in.token == CATCH) {
1017+
val pos = in.offset
10171018
in.nextToken()
1018-
expr()
1019-
} else EmptyTree
1020-
1021-
// A block ends before RBRACE, if next token is RBRACE, simply add 1
1022-
def realEnd(pos: Position) =
1023-
if (in.token == RBRACE) pos.end + 1
1024-
else pos.end
1019+
(expr(), pos)
1020+
} else (EmptyTree, -1)
10251021

10261022
handler match {
1027-
case Block(Nil, EmptyTree) => syntaxError(
1028-
new EmptyCatchBlock(body),
1029-
Position(tryOffset, realEnd(handler.pos))
1030-
)
1023+
case Block(Nil, EmptyTree) =>
1024+
assert(handlerStart != -1)
1025+
syntaxError(
1026+
new EmptyCatchBlock(body),
1027+
Position(handlerStart, handler.pos.end)
1028+
)
10311029
case _ =>
10321030
}
10331031

@@ -1036,7 +1034,7 @@ object Parsers {
10361034
else {
10371035
if (handler.isEmpty) warning(
10381036
EmptyCatchAndFinallyBlock(body),
1039-
source atPos Position(tryOffset, realEnd(body.pos))
1037+
source atPos Position(tryOffset, body.pos.end)
10401038
)
10411039
EmptyTree
10421040
}

src/dotty/tools/dotc/util/SourcePosition.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extends interfaces.SourcePosition {
1717

1818
/** The lines of the position */
1919
def lines: List[Int] =
20-
List.range(source.offsetToLine(start), source.offsetToLine(end)) match {
20+
List.range(source.offsetToLine(start), source.offsetToLine(end + 1)) match {
2121
case Nil => line :: Nil
2222
case xs => xs
2323
}

0 commit comments

Comments
 (0)