From 6de011cc6ee1fd6c9dfb65dd6ab536ded42e013e Mon Sep 17 00:00:00 2001 From: David Date: Mon, 9 Oct 2023 14:07:13 +0200 Subject: [PATCH 1/2] Fix warning underlining in global init checker --- .../src/dotty/tools/dotc/transform/init/Trace.scala | 2 +- tests/init-global/neg/line-spacing.check | 13 +++++++++++++ tests/init-global/neg/line-spacing.scala | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/init-global/neg/line-spacing.check create mode 100644 tests/init-global/neg/line-spacing.scala 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..7a29f88ba6a1 --- /dev/null +++ b/tests/init-global/neg/line-spacing.scala @@ -0,0 +1,12 @@ +object A { + def a: Int = + B + .s.length // error +} + +object B { + val s: String = s"${A.a}a" +} + +@main +def Test = print(A.a) From 6f88c31c6bf7c2a73cbf184625b29f6d6d8a1c65 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 9 Oct 2023 14:10:09 +0200 Subject: [PATCH 2/2] Remote unnecessary lines --- tests/init-global/neg/line-spacing.scala | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/init-global/neg/line-spacing.scala b/tests/init-global/neg/line-spacing.scala index 7a29f88ba6a1..42474decb53c 100644 --- a/tests/init-global/neg/line-spacing.scala +++ b/tests/init-global/neg/line-spacing.scala @@ -7,6 +7,3 @@ object A { object B { val s: String = s"${A.a}a" } - -@main -def Test = print(A.a)