Skip to content

Commit cea01aa

Browse files
committed
fix: scoverage statement's line number should be 1-base
fix #18916 This PR makes scoverage statements' line number 1-base, instead of 0-base, as @tarao described. It would be ideal if we could find specifications of many of coverage report fomats (such as Jacoco XML, cobertura.xml, lcov.txt...) and confirm most of them expect the line numbers 1-base. However, it seems there's no formal specification for them AFAIK. Since we've been using 1-base so far in Scala2 and it hasn't been a problem, so I guess it's OK to change to 1-base (and most of coverage report format and visualizer expect 1-base maybe). I believe it should be reporter / aggregator's responsibility to adjust the line numbers if some coverage format expects 0-base.
1 parent 18ada51 commit cea01aa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compiler/src/dotty/tools/dotc/transform/InstrumentCoverage.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ class InstrumentCoverage extends MacroTransform with IdentityDenotTransformer:
9797
id = id,
9898
start = pos.start,
9999
end = pos.end,
100-
line = pos.line,
100+
// +1 to account for the line number starting at 1
101+
// the internal line number is 0-base https://github.com/lampepfl/dotty/blob/18ada516a85532524a39a962b2ddecb243c65376/compiler/src/dotty/tools/dotc/util/SourceFile.scala#L173-L176
102+
line = pos.line + 1,
101103
desc = sourceFile.content.slice(pos.start, pos.end).mkString,
102104
symbolName = tree.symbol.name.toSimpleName.toString,
103105
treeName = tree.getClass.getSimpleName.nn,

0 commit comments

Comments
 (0)