-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/cover: incomplete coverage when using goto #16624
Comments
/cc @robpike |
Nice. I forgot about goto statements. Should be easy to fix. |
I looked into this for a while because it was biting me as well. Not being familiar with the code I wasn't able to create a quick fix but here's what I learned. The shortcoming is in how labeled statements are handled. The logic is all there for statements that can be departure points for control flow (i.e., goto statements are not the problem), but the logic is missing for statements that can be arrival points for control flow (i.e., labeled statements are the problem). The problem can be understood by considering a labeled statement that can itself affect control flow:
The instrumentation must insert a counter between the label and the statement, but this is delicate surgery because in the ast representation the label contains the statement. The label could be removed from the flowChangingStmt and attached to an immediately preceding new counter statement. However, labeled 'for','switch',or 'select' statements must not have their label removed. It may be that the 'for', 'switch', and 'select' statements are not harmed by the lack of a counter between the label and the statement, so inserting the counter and re-attaching the label may only be necessary for non-'for','switch','select' statements. I hope this helps. Unfortunately I don't have time to dig deeper. An example file and its as-presently-created cover rewrite are shown below.
|
CL https://golang.org/cl/30977 mentions this issue. |
In
go version go1.6.3 linux/amd64
, the following code produces an incomplete cover profile.Both
1
and2
are successfully returned, so I expected to see 100% coverage. However, neither the labels norreturn
statements are accounted for:The text was updated successfully, but these errors were encountered: