Skip to content

Commit 01d627a

Browse files
committed
Fix lines method of SourcePosition
and make it return a range.
1 parent 59f724f commit 01d627a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ extends interfaces.SourcePosition with Showable {
2929
source.content.slice(source.startOfLine(start), source.nextLine(end))
3030

3131
/** The lines of the position */
32-
def lines: List[Int] = {
32+
def lines: Range = {
3333
val startOffset = source.offsetToLine(start)
34-
val endOffset = source.offsetToLine(end + 1)
35-
if (startOffset >= endOffset) line :: Nil
36-
else (startOffset until endOffset).toList
34+
val endOffset = source.offsetToLine(end - 1) // -1 to drop a line if no chars in it form part of the position
35+
if (startOffset >= endOffset) line to line
36+
else startOffset to endOffset
3737
}
3838

3939
def lineOffsets: List[Int] =
40-
lines.map(source.lineToOffset(_))
40+
lines.toList.map(source.lineToOffset(_))
4141

4242
def beforeAndAfterPoint: (List[Int], List[Int]) =
4343
lineOffsets.partition(_ <= point)

tests/neg/i7028.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Test {
2+
"abc"
3+
.foo // error
4+
5+
"abc"
6+
.bar.baz // error
7+
8+
"abc"
9+
.bar // error
10+
.baz
11+
}

0 commit comments

Comments
 (0)