Skip to content

Commit 3f89c26

Browse files
authored
Backport "fix: scoverage statement's line number should be 1-base" to LTS (#19236)
Backports #18932 to the LTS branch. PR submitted by the release tooling.
2 parents edb070b + 12468e3 commit 3f89c26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+443
-490
lines changed

Diff for: compiler/src/dotty/tools/dotc/coverage/Coverage.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ class Coverage:
1111

1212
def addStatement(stmt: Statement): Unit = statementsById(stmt.id) = stmt
1313

14-
/** A statement that can be invoked, and thus counted as "covered" by code coverage tools. */
14+
15+
/**
16+
* A statement that can be invoked, and thus counted as "covered" by code coverage tools.
17+
*
18+
* @param line 1-indexed line number
19+
*/
1520
case class Statement(
1621
location: Location,
1722
id: Int,

Diff for: compiler/src/dotty/tools/dotc/transform/InstrumentCoverage.scala

+3-1
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,

Diff for: tests/coverage/pos/Constructor.scoverage.check

+13-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ covtest.C
2727
<init>
2828
28
2929
36
30-
3
30+
4
3131
<init>
3232
DefDef
3333
false
@@ -44,7 +44,7 @@ covtest.C
4444
<init>
4545
69
4646
72
47-
5
47+
6
4848
g
4949
Apply
5050
false
@@ -61,7 +61,7 @@ covtest.C
6161
<init>
6262
80
6363
88
64-
8
64+
9
6565
<init>
6666
DefDef
6767
false
@@ -78,7 +78,7 @@ covtest.C
7878
<init>
7979
108
8080
128
81-
9
81+
10
8282
+
8383
Apply
8484
false
@@ -95,7 +95,7 @@ covtest.C
9595
f
9696
133
9797
138
98-
11
98+
12
9999
f
100100
DefDef
101101
false
@@ -112,7 +112,7 @@ covtest.C
112112
x
113113
153
114114
158
115-
12
115+
13
116116
x
117117
DefDef
118118
false
@@ -129,7 +129,7 @@ covtest.C
129129
<init>
130130
165
131131
169
132-
13
132+
14
133133
f
134134
Apply
135135
false
@@ -146,7 +146,7 @@ covtest.C
146146
<init>
147147
167
148148
168
149-
13
149+
14
150150
x
151151
Select
152152
false
@@ -163,7 +163,7 @@ covtest.C
163163
g
164164
173
165165
178
166-
15
166+
16
167167
g
168168
DefDef
169169
false
@@ -180,7 +180,7 @@ covtest.O$
180180
g
181181
203
182182
208
183-
18
183+
19
184184
g
185185
DefDef
186186
false
@@ -197,7 +197,7 @@ covtest.O$
197197
y
198198
223
199199
228
200-
19
200+
20
201201
y
202202
DefDef
203203
false
@@ -214,7 +214,7 @@ covtest.O$
214214
<init>
215215
235
216216
239
217-
20
217+
21
218218
g
219219
Apply
220220
false
@@ -231,7 +231,7 @@ covtest.O$
231231
<init>
232232
237
233233
238
234-
20
234+
21
235235
y
236236
Ident
237237
false

Diff for: tests/coverage/pos/ContextFunctions.scoverage.check

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ covtest.OnError
2727
onError
2828
56
2929
67
30-
3
30+
4
3131
onError
3232
DefDef
3333
false
@@ -44,7 +44,7 @@ covtest.Imperative
4444
readName2
4545
121
4646
134
47-
7
47+
8
4848
readName2
4949
DefDef
5050
false
@@ -61,7 +61,7 @@ covtest.Imperative
6161
readPerson
6262
252
6363
309
64-
13
64+
14
6565
onError
6666
Apply
6767
false
@@ -78,7 +78,7 @@ covtest.Imperative
7878
readPerson
7979
252
8080
295
81-
13
81+
14
8282
<init>
8383
Apply
8484
false
@@ -95,7 +95,7 @@ covtest.Imperative
9595
$anonfun
9696
267
9797
294
98-
13
98+
14
9999
apply
100100
Apply
101101
false
@@ -112,7 +112,7 @@ covtest.Imperative
112112
readPerson
113113
192
114114
206
115-
11
115+
12
116116
readPerson
117117
DefDef
118118
false

Diff for: tests/coverage/pos/Enum.scoverage.check

+17-17
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ covtest.Planet
2727
surfaceGravity
2828
338
2929
356
30-
14
30+
15
3131
surfaceGravity
3232
DefDef
3333
false
@@ -44,7 +44,7 @@ covtest.Planet
4444
surfaceWeight
4545
444
4646
458
47-
15
47+
16
4848
surfaceGravity
4949
Select
5050
false
@@ -61,7 +61,7 @@ covtest.Planet
6161
surfaceWeight
6262
392
6363
409
64-
15
64+
16
6565
surfaceWeight
6666
DefDef
6767
false
@@ -78,7 +78,7 @@ covtest.EnumTypes$
7878
test
7979
1043
8080
1077
81-
30
81+
31
8282
println
8383
Apply
8484
false
@@ -95,7 +95,7 @@ covtest.EnumTypes$
9595
test
9696
1051
9797
1076
98-
30
98+
31
9999
+
100100
Apply
101101
false
@@ -112,7 +112,7 @@ covtest.EnumTypes$
112112
test
113113
1082
114114
1103
115-
31
115+
32
116116
println
117117
Apply
118118
false
@@ -129,7 +129,7 @@ covtest.EnumTypes$
129129
test
130130
1090
131131
1102
132-
31
132+
32
133133
s
134134
Apply
135135
false
@@ -146,7 +146,7 @@ covtest.EnumTypes$
146146
calculateEarthWeightOnPlanets
147147
1195
148148
1222
149-
34
149+
35
150150
surfaceGravity
151151
Select
152152
false
@@ -163,7 +163,7 @@ covtest.EnumTypes$
163163
calculateEarthWeightOnPlanets
164164
1229
165165
1320
166-
35
166+
36
167167
foreach
168168
Apply
169169
false
@@ -180,7 +180,7 @@ covtest.EnumTypes$
180180
calculateEarthWeightOnPlanets
181181
1238
182182
1251
183-
35
183+
36
184184
refArrayOps
185185
Apply
186186
false
@@ -197,7 +197,7 @@ covtest.EnumTypes$
197197
$anonfun
198198
1263
199199
1320
200-
36
200+
37
201201
println
202202
Apply
203203
false
@@ -214,7 +214,7 @@ covtest.EnumTypes$
214214
$anonfun
215215
1271
216216
1319
217-
36
217+
37
218218
s
219219
Apply
220220
false
@@ -231,7 +231,7 @@ covtest.EnumTypes$
231231
$anonfun
232232
1296
233233
1317
234-
36
234+
37
235235
surfaceWeight
236236
Apply
237237
false
@@ -248,7 +248,7 @@ covtest.EnumTypes$
248248
calculateEarthWeightOnPlanets
249249
1109
250250
1142
251-
33
251+
34
252252
calculateEarthWeightOnPlanets
253253
DefDef
254254
false
@@ -265,7 +265,7 @@ covtest.EnumTypes$
265265
test
266266
1326
267267
1347
268-
38
268+
39
269269
println
270270
Apply
271271
false
@@ -282,7 +282,7 @@ covtest.EnumTypes$
282282
test
283283
1352
284284
1385
285-
39
285+
40
286286
calculateEarthWeightOnPlanets
287287
Apply
288288
false
@@ -299,7 +299,7 @@ covtest.EnumTypes$
299299
test
300300
901
301301
909
302-
27
302+
28
303303
test
304304
DefDef
305305
false

Diff for: tests/coverage/pos/Escaping.scoverage.check

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ covtest.\n.\r\n\f
2727
\r\n\f
2828
69
2929
80
30-
3
30+
4
3131
length
3232
Apply
3333
false
@@ -44,7 +44,7 @@ covtest.\n.\r\n\f
4444
\r\n\f
4545
40
4646
48
47-
3
47+
4
4848
\r\n\f
4949
DefDef
5050
false

0 commit comments

Comments
 (0)