Skip to content
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

Improve branch detection for lambda functions and async/await statements #702

Merged

Conversation

matteoerigozzi
Copy link
Contributor

@matteoerigozzi matteoerigozzi commented Jan 24, 2020

Fixes #584

In case of nested compiler generated classes, only the root one presents the CompilerGeneratedAttribute

image

So to detect the MoveNext() method inside an async state machine we need to check recoursively the declaring type for compiler generated attribute.

I also noticed that the operand of the instruction ldfld inside an async state machine prolog can be FieldDefinition or FieldReference.
We can see the difference looking at generated IL:

image

image

After this updates we removed some unexpected branches generates by async state machines and the report is this
image

Here I propose a solution to remove last 2 unexpected branches, that seems to be generated invoking a method with a delegate parameter. I added more tests to check the fairness but I'm not completely sure about it.

@MarcoRossignoli MarcoRossignoli added enhancement General enhancement request tenet-coverage Issue related to possible incorrect coverage bug Something isn't working and removed enhancement General enhancement request labels Jan 24, 2020
@MarcoRossignoli
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Collaborator

@MarcoRossignoli MarcoRossignoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine!Thank's!

@MarcoRossignoli MarcoRossignoli merged commit 3d9be6f into coverlet-coverage:master Jan 28, 2020
@matteoerigozzi matteoerigozzi deleted the Lambda_Issue343 branch January 28, 2020 10:17
@nycdotnet
Copy link

Thanks so much for this fix and 2.8.1 - it really cleaned up some of our coverage stats.

@MarcoRossignoli
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tenet-coverage Issue related to possible incorrect coverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected branches reported for async lambda expression
3 participants