Skip to content

Commit

Permalink
Fix lines method of SourcePosition
Browse files Browse the repository at this point in the history
and make it return a range.
  • Loading branch information
odersky committed Aug 12, 2019
1 parent b221132 commit 259233a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/util/SourcePosition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ extends interfaces.SourcePosition with Showable {
source.content.slice(source.startOfLine(start), source.nextLine(end))

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

def lineOffsets: List[Int] =
lines.map(source.lineToOffset(_))
lines.toList.map(source.lineToOffset(_))

def beforeAndAfterPoint: (List[Int], List[Int]) =
lineOffsets.partition(_ <= point)
Expand Down
11 changes: 11 additions & 0 deletions tests/neg/i7028.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object Test {
"abc"
.foo // error

"abc"
.bar.baz // error

"abc"
.bar // error
.baz
}

0 comments on commit 259233a

Please sign in to comment.