Skip to content

Commit 528fd8e

Browse files
committed
Fix #14240: Fix off-by-1 when emitting Scala.js IR Positions.
scalac positions are 1-based, while IR positions are 0-based. There is therefore a `- 1` in the nsc plugin, that was ported over to dotc without questioning. It turns out that dotc uses 0-based positions as well (as documented in `SourceFile`), and so we should not make any adaptation there.
1 parent c49a1cf commit 528fd8e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compiler/src/dotty/tools/backend/sjs/JSPositions.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class JSPositions()(using Context) {
3939
private def sourceAndSpan2irPos(source: SourceFile, span: Span): ir.Position = {
4040
if (!span.exists) ir.Position.NoPosition
4141
else {
42-
// dotty positions are 1-based but IR positions are 0-based
42+
// dotty positions and IR positions are both 0-based
4343
val irSource = span2irPosCache.toIRSource(source)
4444
val point = span.point
45-
val line = source.offsetToLine(point) - 1
46-
val column = source.column(point) - 1
45+
val line = source.offsetToLine(point)
46+
val column = source.column(point)
4747
ir.Position(irSource, line, column)
4848
}
4949
}

0 commit comments

Comments
 (0)