Fix #72884: don't report IDE0052 on written-through ref-returning properties#84316
Draft
jcouv wants to merge 2 commits into
Draft
Fix #72884: don't report IDE0052 on written-through ref-returning properties#84316jcouv wants to merge 2 commits into
jcouv wants to merge 2 commits into
Conversation
added 2 commits
June 27, 2026 18:38
…urning property incremented via A++
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.
Fixes #72884.
Problem
IDE0052 (
Private member can be removed as the value assigned to it is never read) was a false positive on a private writable ref-returning property that is written through:A++invokes the property getter to obtain theref intand writes through the returned reference. There is no setter, so the property is genuinely read on every access and IDE0052 must not fire.A = xandA += ywere affected the same way, as were ref-returning indexers.Fix
In
AbstractRemoveUnusedMembersDiagnosticAnalyzer.AnalyzeMemberReferenceOperation, a writable ref-returning property/indexer reference always retains its Read bit (its getter is always invoked), so it is never downgraded to write-only:RefKind.RefReadOnlyis correctly excluded (it cannot be written through). Genuinely unreferenced ref properties still surface IDE0051 since they never reach this method.Tests
Added regression tests covering
A++,A += y,A = x, and a ref-returning indexer (all expect no diagnostic), plus the existing read-only control. Verified ordinary write-only property increments still flag (no regression). FullRemoveUnusedMemberssuite: 271 passed.Microsoft Reviewers: Open in CodeFlow