Skip to content

Commit e1b5451

Browse files
authored
Fix warning underlining in global init checker (#18668)
Fixes the placement of the caret when the global init checker reports warnings for multi-line statements.
2 parents db7e033 + 6f88c31 commit e1b5451

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

compiler/src/dotty/tools/dotc/transform/init/Trace.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ object Trace:
7777
* pos.source must exist
7878
*/
7979
private def positionMarker(pos: SourcePosition): String =
80-
val trimmed = pos.lineContent.takeWhile(c => c.isWhitespace).length
80+
val trimmed = pos.source.lineContent(pos.start).takeWhile(c => c.isWhitespace).length
8181
val padding = pos.startColumnPadding.substring(trimmed).nn + " "
8282
val carets =
8383
if (pos.startLine == pos.endLine)
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Error: tests/init-global/neg/line-spacing.scala:4:7 -----------------------------------------------------------------
2+
3 | B
3+
4 | .s.length // error
4+
| ^
5+
| Access uninitialized field value s. Call trace:
6+
| -> object B { [ line-spacing.scala:7 ]
7+
| ^
8+
| -> val s: String = s"${A.a}a" [ line-spacing.scala:8 ]
9+
| ^^^
10+
| -> def a: Int = [ line-spacing.scala:2 ]
11+
| ^
12+
| -> .s.length // error [ line-spacing.scala:4 ]
13+
| ^
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object A {
2+
def a: Int =
3+
B
4+
.s.length // error
5+
}
6+
7+
object B {
8+
val s: String = s"${A.a}a"
9+
}

0 commit comments

Comments
 (0)