Skip to content

Commit

Permalink
Fix warning underlining in global init checker (#18668)
Browse files Browse the repository at this point in the history
Fixes the placement of the caret when the global init checker reports
warnings for multi-line statements.
  • Loading branch information
olhotak authored Oct 10, 2023
2 parents db7e033 + 6f88c31 commit e1b5451
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions tests/init-global/neg/line-spacing.check
Original file line number Diff line number Diff line change
@@ -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 ]
| ^
9 changes: 9 additions & 0 deletions tests/init-global/neg/line-spacing.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object A {
def a: Int =
B
.s.length // error
}

object B {
val s: String = s"${A.a}a"
}

0 comments on commit e1b5451

Please sign in to comment.