Repository navigation
fix(primitives): preserve nullable flow analysis in static SubscribeSafe calls - #250
Merged
Merged
Conversation
…afe calls - Relax the class-constrained static SubscribeSafe and SubscribeSafeWitness.Subscribe overloads to unconstrained T so nullable reference sources keep Action<T?> and IObserver<T?> instead of erasing nullability via null-forgiving wrappers. - Raise the struct-constrained SubscribeSafe and SubscribeSafeWitness.Subscribe overloads to OverloadResolutionPriority(2) so non-nullable and nullable value types continue dispatching unambiguously without breaking binary compatibility. - Remove the redundant value => onNext(value!) wrapper closures in SubscribeSafeWitness.Subscribe and add Roslyn consumer tests verifying CS8602, CS8620, and CS8622 diagnostics.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #250 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1013 1013
Lines 27209 27204 -5
Branches 3278 3278
=========================================
- Hits 27209 27204 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
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
This PR preserves C# nullable reference flow analysis on static
LinqExtensions.SubscribeSafeandSubscribeSafeWitness.Subscribecalls without breaking binary compatibility.where T : classstaticSubscribeSafeandSubscribeSafeWitness.Subscribeoverloads from(IObservable<T?>, Action<T> / IObserver<T>)to unconstrainedT((IObservable<T>, Action<T> / IObserver<T>)) soTcarries[Nullable(2)]in metadata and removes thevalue => onNext(value!)wrapper closures.[OverloadResolutionPriority(2)]on the existingwhere T : structoverloads so non-nullable and nullable value types keep dispatching unambiguously alongside the unconstrainedToverloads.Refs #129
Why
The previous
where T : classstatic overloads acceptedIObservable<T?>while typingonNextandobserveras non-nullableAction<T>andIObserver<T>, forwarding values throughvalue => onNext(value!)and(IObserver<T?>)observer. CallingLinqExtensions.SubscribeSafeorSubscribeSafeWitness.Subscribestatically on a nullable reference sequence suppressedCS8602,CS8620, andCS8622at compile time, allocated an extra closure per subscription, and passednullinto non-nullable handlers at runtime.Breaking changes
None
How this was verified
Built
ReactiveUI.Primitives.slnfandReactiveUI.Primitives.Uno.slnfacross all target frameworks, randetect-duplicatesagainstmain, ran the full test suite with Cobertura coverage, and added Roslyn consumer compilation tests verifying clean nullable/non-nullable dispatch as well asCS8602,CS8620, andCS8622warnings when handlers rejectnull.Notes for the reviewer
SignalOperatorParityMixins.RxNames.SubscribeSafe.csandSubscribeSafeWitness.cs.where T : classto unconstrainedTpreserves the exact CLR metadata signature (IObservable<!0>,Action<!0>/IObserver<!0>,bool[]) for compiled callers while restoring[Nullable(2)]onTfor C# source callers.Checklist