Skip to content

Commit 98d9e9c

Browse files
Coverage: handle TypeApply in a more robust way, fix #15771
1 parent 731522a commit 98d9e9c

30 files changed

+1612
-745
lines changed

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

Lines changed: 275 additions & 165 deletions
Large diffs are not rendered by default.

tests/coverage/pos/Constructor.scoverage.check

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ C
5959
Class
6060
covtest.C
6161
<init>
62-
62
63-
63
62+
60
63+
64
6464
5
65-
x
66-
Select
65+
f
66+
Apply
6767
false
6868
0
6969
false
70-
x
70+
f(x)
7171

7272
3
7373
Constructor.scala
@@ -76,15 +76,15 @@ C
7676
Class
7777
covtest.C
7878
<init>
79-
60
80-
64
79+
62
80+
63
8181
5
82-
f
83-
Apply
82+
x
83+
Select
8484
false
8585
0
8686
false
87-
f(x)
87+
x
8888

8989
4
9090
Constructor.scala
@@ -127,15 +127,15 @@ O$
127127
Object
128128
covtest.O$
129129
<init>
130-
112
131-
113
130+
110
131+
114
132132
10
133-
y
134-
Ident
133+
g
134+
Apply
135135
false
136136
0
137137
false
138-
y
138+
g(y)
139139

140140
7
141141
Constructor.scala
@@ -144,13 +144,13 @@ O$
144144
Object
145145
covtest.O$
146146
<init>
147-
110
148-
114
147+
112
148+
113
149149
10
150-
g
151-
Apply
150+
y
151+
Ident
152152
false
153153
0
154154
false
155-
g(y)
155+
y
156156

tests/coverage/pos/ContextFunctions.scoverage.check

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,40 @@ Imperative
7676
Class
7777
covtest.Imperative
7878
readPerson
79+
252
80+
295
81+
13
82+
<init>
83+
Apply
84+
false
85+
0
86+
false
87+
OnError((e) => readName2(using e)(using s))
88+
89+
4
90+
ContextFunctions.scala
91+
covtest
92+
Imperative
93+
Class
94+
covtest.Imperative
95+
$anonfun
96+
267
97+
294
98+
13
99+
apply
100+
Apply
101+
false
102+
0
103+
false
104+
readName2(using e)(using s)
105+
106+
5
107+
ContextFunctions.scala
108+
covtest
109+
Imperative
110+
Class
111+
covtest.Imperative
112+
readPerson
79113
192
80114
206
81115
11

tests/coverage/pos/Enum.scoverage.check

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ EnumTypes$
212212
Object
213213
covtest.EnumTypes$
214214
test
215-
1051
216-
1076
215+
1043
216+
1077
217217
30
218-
+
218+
println
219219
Apply
220220
false
221221
0
222222
false
223-
"Example 1: \n"+emptyList
223+
println("Example 1: \n"+emptyList)
224224

225225
12
226226
Enum.scala
@@ -229,15 +229,15 @@ EnumTypes$
229229
Object
230230
covtest.EnumTypes$
231231
test
232-
1043
233-
1077
232+
1051
233+
1076
234234
30
235-
println
235+
+
236236
Apply
237237
false
238238
0
239239
false
240-
println("Example 1: \n"+emptyList)
240+
"Example 1: \n"+emptyList
241241

242242
13
243243
Enum.scala
@@ -246,15 +246,15 @@ EnumTypes$
246246
Object
247247
covtest.EnumTypes$
248248
test
249-
1090
250-
1102
249+
1082
250+
1103
251251
31
252-
s
252+
println
253253
Apply
254254
false
255255
0
256256
false
257-
s"${list}\n"
257+
println(s"${list}\n")
258258

259259
14
260260
Enum.scala
@@ -263,15 +263,15 @@ EnumTypes$
263263
Object
264264
covtest.EnumTypes$
265265
test
266-
1082
267-
1103
266+
1090
267+
1102
268268
31
269-
println
269+
s
270270
Apply
271271
false
272272
0
273273
false
274-
println(s"${list}\n")
274+
s"${list}\n"
275275

276276
15
277277
Enum.scala
@@ -297,32 +297,33 @@ EnumTypes$
297297
Object
298298
covtest.EnumTypes$
299299
calculateEarthWeightOnPlanets
300-
1238
301-
1251
300+
1229
301+
1320
302302
35
303-
refArrayOps
303+
foreach
304304
Apply
305305
false
306306
0
307307
false
308-
Planet.values
308+
for p <- Planet.values do
309+
println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
309310

310311
17
311312
Enum.scala
312313
covtest
313314
EnumTypes$
314315
Object
315316
covtest.EnumTypes$
316-
$anonfun
317-
1296
318-
1317
319-
36
320-
surfaceWeight
317+
calculateEarthWeightOnPlanets
318+
1238
319+
1251
320+
35
321+
refArrayOps
321322
Apply
322323
false
323324
0
324325
false
325-
p.surfaceWeight(mass)
326+
Planet.values
326327

327328
18
328329
Enum.scala
@@ -331,15 +332,15 @@ EnumTypes$
331332
Object
332333
covtest.EnumTypes$
333334
$anonfun
334-
1271
335-
1319
335+
1263
336+
1320
336337
36
337-
s
338+
println
338339
Apply
339340
false
340341
0
341342
false
342-
s"Your weight on $p is ${p.surfaceWeight(mass)}"
343+
println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
343344

344345
19
345346
Enum.scala
@@ -348,33 +349,32 @@ EnumTypes$
348349
Object
349350
covtest.EnumTypes$
350351
$anonfun
351-
1263
352-
1320
352+
1271
353+
1319
353354
36
354-
println
355+
s
355356
Apply
356357
false
357358
0
358359
false
359-
println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
360+
s"Your weight on $p is ${p.surfaceWeight(mass)}"
360361

361362
20
362363
Enum.scala
363364
covtest
364365
EnumTypes$
365366
Object
366367
covtest.EnumTypes$
367-
calculateEarthWeightOnPlanets
368-
1229
369-
1320
370-
35
371-
foreach
368+
$anonfun
369+
1296
370+
1317
371+
36
372+
surfaceWeight
372373
Apply
373374
false
374375
0
375376
false
376-
for p <- Planet.values do
377-
println(s"Your weight on $p is ${p.surfaceWeight(mass)}")
377+
p.surfaceWeight(mass)
378378

379379
21
380380
Enum.scala
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package covtest
2+
3+
enum MyLogLevel extends java.lang.Enum[MyLogLevel]:
4+
case Warn extends MyLogLevel
5+
case Error extends MyLogLevel
6+
case Fatal extends MyLogLevel

tests/coverage/pos/For.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package covtest
2+
3+
def testForLoop: Unit =
4+
for i <- 1 to 10 do
5+
println(i)
6+
7+
def testForAdvanced: Unit =
8+
def f(x: Int): Boolean = true
9+
for j <- 1 to 10 if f(j) do
10+
println(j)
11+
12+
def testForeach: Unit =
13+
// An anonymous function is created here, but the user code must still be instrumented!
14+
Nil.foreach(_ => println("user code here"))

0 commit comments

Comments
 (0)