Skip to content

Remove inverted nullable-state annotation on IDeprecationProvider - #10165

Merged
glen-84 merged 1 commit into
mainfrom
gai/remove-inverted-deprecation-annotation
Jul 29, 2026
Merged

Remove inverted nullable-state annotation on IDeprecationProvider#10165
glen-84 merged 1 commit into
mainfrom
gai/remove-inverted-deprecation-annotation

Conversation

@glen-84

@glen-84 glen-84 commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

  • IDeprecationProvider.IsDeprecated was annotated [MemberNotNullWhen(false, nameof(DeprecationReason))], telling the compiler that DeprecationReason is non-null when a member is not deprecated. That suppressed nullable diagnostics in precisely the branch where the value is always null, so dereferencing DeprecationReason inside an if (!IsDeprecated) branch compiled clean and could throw at runtime.
  • The annotation is removed rather than inverted. IsDeprecated and DeprecationReason are 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.
  • Annotation-only: no runtime behavior change, and callers that already null-check are unaffected.

Test plan

  • dotnet build src/All.slnx is clean across Core, Mutable, and Fusion.
  • The repo escalates nullable diagnostics to errors via WarningsAsErrors=nullable, so any site that depended on the removed annotation would surface as a CS8602 build error. None did, confirming no reads of DeprecationReason were relying on the false non-null guarantee.
  • No test accompanies the change: it affects compile-time nullable flow analysis only, and there is no runtime behavior that differs before and after for a test to assert.

Copilot AI review requested due to automatic review settings July 29, 2026 12:52

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 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 from IsDeprecated.
  • Removed the now-unused System.Diagnostics.CodeAnalysis using.
  • Clarified XML docs for DeprecationReason to explicitly allow null when no reason is provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@glen-84
glen-84 merged commit acbf90e into main Jul 29, 2026
148 checks passed
@glen-84
glen-84 deleted the gai/remove-inverted-deprecation-annotation branch July 29, 2026 13:01
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.

2 participants