Repository navigation
Handle FieldReference in delegate cache branch detection - #1938
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates coverlet’s Cecil-based branch filtering to correctly recognize compiler-generated delegate/lambda cache fields when Cecil exposes the operand as a FieldReference (not just FieldDefinition), preventing phantom branches from appearing in coverage reports. It also adds a focused regression sample and coverage test for issue #1937.
Changes:
- Extend cached-field branch skipping logic in
CecilSymbolHelperto handle bothFieldDefinitionandFieldReference. - Add a new instrumentation sample (
Issue_1937) that reproduces delegate-cache null-check phantom branch behavior. - Add a regression test validating the expected branch count for the sample.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/coverlet.core.coverage.tests/Samples/Instrumentation.Lambda.cs | Adds a new sample type reproducing issue #1937’s lambda/delegate-cache branch scenario. |
| test/coverlet.core.coverage.tests/Coverage/CoverageTests.Lambda.cs | Adds a regression test asserting the expected total branch count for the new sample. |
| src/coverlet.core/Symbols/CecilSymbolHelper.cs | Updates cached-field detection to accept FieldReference operands (via helper methods) to avoid phantom branches. |
Improve CecilSymbolHelper to detect both FieldDefinition and FieldReference for compiler-generated delegate cache fields, preventing phantom branches in coverage. Add regression test and sample for issue coverlet-coverage#1937 to ensure only real user-code branches are reported.
Clarified and strengthened the test for issue coverlet-coverage#1937 in CoverageTests.Lambda.cs to ensure only the real user-code `if` branch inside the lambda (line 160) is reported. Added assertions to verify both true and false paths are covered exactly once, and enhanced comments for intent and clarity.
Added a fix for regression in branch coverage for lambda expressions.
This was referenced Sep 27, 2026
This was referenced Oct 10, 2026
Open
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Improve CecilSymbolHelper to detect both FieldDefinition and FieldReference for compiler-generated delegate cache fields, preventing phantom branches in coverage. Add regression test and sample for issue #1937 to ensure only real user-code branches are reported.