Skip to content

Handle FieldReference in delegate cache branch detection - #1938

Merged
Bertk merged 3 commits into
coverlet-coverage:masterfrom
Bertk:fix-issue-1937
May 19, 2026
Merged

Bertk merged 3 commits into
coverlet-coverage:masterfrom
Bertk:fix-issue-1937

Conversation

@Bertk

@Bertk Bertk commented May 19, 2026

Copy link
Copy Markdown
Collaborator

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.

Copilot AI review requested due to automatic review settings May 19, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 CecilSymbolHelper to handle both FieldDefinition and FieldReference.
  • 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.

Comment thread test/coverlet.core.coverage.tests/Coverage/CoverageTests.Lambda.cs
Bertk added 2 commits May 19, 2026 19:27
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.
@Bertk
Bertk force-pushed the fix-issue-1937 branch from b891d91 to 8d9fce1 Compare May 19, 2026 17:27
Added a fix for regression in branch coverage for lambda expressions.
@Bertk
Bertk merged commit 5654ffe into coverlet-coverage:master May 19, 2026
12 checks passed
@Bertk
Bertk deleted the fix-issue-1937 branch May 19, 2026 19:50
@Bertk Bertk linked an issue Jul 25, 2026 that may be closed by this pull request
This was referenced Sep 27, 2026
This was referenced Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Regression in branch coverage for lambda expressions in v10.0.1

2 participants