Remove inverted nullable-state annotation on IDeprecationProvider - #10165
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR corrects nullable flow analysis for IDeprecationProvider by removing an incorrect [MemberNotNullWhen] annotation that implied DeprecationReason is non-null in the non-deprecated branch, which is the opposite of expected semantics and could hide null-dereference risks at compile time.
Changes:
- Removed the inverted
[MemberNotNullWhen(false, nameof(DeprecationReason))]annotation fromIsDeprecated. - Removed the now-unused
System.Diagnostics.CodeAnalysisusing. - Clarified XML docs for
DeprecationReasonto explicitly allownullwhen no reason is provided.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Aug 9, 2026
Merged
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.
Summary
IDeprecationProvider.IsDeprecatedwas annotated[MemberNotNullWhen(false, nameof(DeprecationReason))], telling the compiler thatDeprecationReasonis non-null when a member is not deprecated. That suppressed nullable diagnostics in precisely the branch where the value is always null, so dereferencingDeprecationReasoninside anif (!IsDeprecated)branch compiled clean and could throw at runtime.IsDeprecatedandDeprecationReasonare independently settable on the Mutable definitions and independently supplied to the Fusion definition constructors, so a member that is deprecated without a reason is a state the API supports. Asserting the opposite would be a promise the type system does not keep, and one the compiler never verifies for interface members.Test plan
dotnet build src/All.slnxis clean across Core, Mutable, and Fusion.WarningsAsErrors=nullable, so any site that depended on the removed annotation would surface as aCS8602build error. None did, confirming no reads ofDeprecationReasonwere relying on the false non-null guarantee.