-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Draft: Fix coverage reporting with for comprehensions #17239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
vijaykramesh
wants to merge
2
commits into
scala:main
from
vijaykramesh:fix_for_comprehension_coverage
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package covtest | ||
|
||
def testForComprehension: Unit = | ||
for { | ||
a <- List(1) | ||
b <- List(1) | ||
if b > 1 | ||
c = a + b | ||
} yield (a, b, c) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
# Coverage data, format version: 3.0 | ||
# Statement data: | ||
# - id | ||
# - source path | ||
# - package name | ||
# - class name | ||
# - class type (Class, Object or Trait) | ||
# - full class name | ||
# - method name | ||
# - start offset | ||
# - end offset | ||
# - line number | ||
# - symbol name | ||
# - tree name | ||
# - is branch | ||
# - invocations count | ||
# - is ignored | ||
# - description (can be multi-line) | ||
# '' sign | ||
# ------------------------------------------ | ||
0 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
testForComprehension | ||
52 | ||
138 | ||
3 | ||
flatMap | ||
Apply | ||
false | ||
0 | ||
false | ||
for {\n a <- List(1)\n b <- List(1)\n if b > 1\n c = a + b\n } yield (a, b, c) | ||
|
||
1 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
testForComprehension | ||
67 | ||
74 | ||
4 | ||
apply | ||
Apply | ||
false | ||
0 | ||
false | ||
List(1) | ||
|
||
2 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
testForComprehension | ||
67 | ||
71 | ||
4 | ||
List | ||
Ident | ||
false | ||
0 | ||
false | ||
List | ||
|
||
3 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
$anonfun | ||
79 | ||
138 | ||
5 | ||
map | ||
Apply | ||
false | ||
0 | ||
false | ||
b <- List(1)\n if b > 1\n c = a + b\n } yield (a, b, c) | ||
|
||
4 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
$anonfun | ||
79 | ||
118 | ||
5 | ||
map | ||
Apply | ||
false | ||
0 | ||
false | ||
b <- List(1)\n if b > 1\n c = a + b | ||
|
||
5 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
$anonfun | ||
79 | ||
104 | ||
5 | ||
withFilter | ||
Apply | ||
false | ||
0 | ||
false | ||
b <- List(1)\n if b > 1 | ||
|
||
6 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
$anonfun | ||
84 | ||
91 | ||
5 | ||
apply | ||
Apply | ||
false | ||
0 | ||
false | ||
List(1) | ||
|
||
7 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
$anonfun | ||
84 | ||
88 | ||
5 | ||
List | ||
Ident | ||
false | ||
0 | ||
false | ||
List | ||
|
||
8 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
$anonfun | ||
79 | ||
110 | ||
5 | ||
apply | ||
Apply | ||
false | ||
0 | ||
false | ||
b <- List(1)\n if b > 1\n c | ||
|
||
9 | ||
ForComprehension.scala | ||
covtest | ||
ForComprehension$package$ | ||
Object | ||
covtest.ForComprehension$package$ | ||
testForComprehension | ||
17 | ||
41 | ||
2 | ||
testForComprehension | ||
DefDef | ||
false | ||
0 | ||
false | ||
def testForComprehension | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it's not that simple, for two reasons:
Select
trees simply cannot be instrumented, because the later phases of the compiler expect some trees to be removed/transformed in some specific ways that aren't compatible with the coverage instrumentation (e.g.asInstanceOf
).tryInstrument(Apply)
, it would be redundant to instrument the select. For instance fora.f(x)
, we get anApply(Select(...), args)
where the Select isa.f
and the args isx
. Here, instrumenting theApply
tree is enough.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks these comments make sense, and indeed as I do more testing I see it's not this simple :)
hopefully will report back after tackling this further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheElectronWill so I'm able to reproduce the issue neatly locally now, and then use my local dotty build in sbt-scoverage-samples in order to clearly see the coverage issue and how my local changes impact it

I am able to get the right side of the flatMap/for comprehension to show up in the measurements file but not arbitrarily deep (so the right hand side of
a <- List(1)
will be green but the right hand side of the next lineb <- List(2)
won't be.& also it somewhat seems fundamentally wrong to me, because we are getting a statement for the whole Apply flatMap tree around everything -
and that is properly getting added to the measurements file when it is called.
so I actually think the "correct" solution would be to stop these other statements (that are inside the flatMap/for comprehension statement) from showing up entirely. does that make sense to you?
statement list to show you the "double counting"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then, how would the coverage check that all of the for-comprehension is executed? The first rhs could fail, and in that case the rest of the for-comprehension must not be 100% covered. For example: