diff --git a/compiler/src/dotty/tools/dotc/transform/init/Trace.scala b/compiler/src/dotty/tools/dotc/transform/init/Trace.scala index 7f3208dae952..98380686c6aa 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Trace.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Trace.scala @@ -77,7 +77,7 @@ object Trace: * pos.source must exist */ private def positionMarker(pos: SourcePosition): String = - val trimmed = pos.lineContent.takeWhile(c => c.isWhitespace).length + val trimmed = pos.source.lineContent(pos.start).takeWhile(c => c.isWhitespace).length val padding = pos.startColumnPadding.substring(trimmed).nn + " " val carets = if (pos.startLine == pos.endLine) diff --git a/tests/init-global/neg/line-spacing.check b/tests/init-global/neg/line-spacing.check new file mode 100644 index 000000000000..ab44d7d1dc65 --- /dev/null +++ b/tests/init-global/neg/line-spacing.check @@ -0,0 +1,13 @@ +-- Error: tests/init-global/neg/line-spacing.scala:4:7 ----------------------------------------------------------------- +3 | B +4 | .s.length // error + | ^ + | Access uninitialized field value s. Call trace: + | -> object B { [ line-spacing.scala:7 ] + | ^ + | -> val s: String = s"${A.a}a" [ line-spacing.scala:8 ] + | ^^^ + | -> def a: Int = [ line-spacing.scala:2 ] + | ^ + | -> .s.length // error [ line-spacing.scala:4 ] + | ^ diff --git a/tests/init-global/neg/line-spacing.scala b/tests/init-global/neg/line-spacing.scala new file mode 100644 index 000000000000..42474decb53c --- /dev/null +++ b/tests/init-global/neg/line-spacing.scala @@ -0,0 +1,9 @@ +object A { + def a: Int = + B + .s.length // error +} + +object B { + val s: String = s"${A.a}a" +}