diff --git a/compiler/src/dotty/tools/dotc/util/SourcePosition.scala b/compiler/src/dotty/tools/dotc/util/SourcePosition.scala index a68531138e94..51dde590c475 100644 --- a/compiler/src/dotty/tools/dotc/util/SourcePosition.scala +++ b/compiler/src/dotty/tools/dotc/util/SourcePosition.scala @@ -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) diff --git a/tests/neg/i7028.scala b/tests/neg/i7028.scala new file mode 100644 index 000000000000..290931370cc6 --- /dev/null +++ b/tests/neg/i7028.scala @@ -0,0 +1,11 @@ +object Test { + "abc" + .foo // error + + "abc" + .bar.baz // error + + "abc" + .bar // error + .baz +} \ No newline at end of file