Skip to content

fix(primitives): preserve nullable flow analysis in static SubscribeSafe calls - #250

Merged
glennawatson merged 1 commit into
mainfrom
fix/subscribe-safe-static-nullability
Nov 21, 2026
Merged

glennawatson merged 1 commit into
mainfrom
fix/subscribe-safe-static-nullability

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

Summary

This PR preserves C# nullable reference flow analysis on static LinqExtensions.SubscribeSafe and SubscribeSafeWitness.Subscribe calls without breaking binary compatibility.

  • Relax the four where T : class static SubscribeSafe and SubscribeSafeWitness.Subscribe overloads from (IObservable<T?>, Action<T> / IObserver<T>) to unconstrained T ((IObservable<T>, Action<T> / IObserver<T>)) so T carries [Nullable(2)] in metadata and removes the value => onNext(value!) wrapper closures.
  • Set [OverloadResolutionPriority(2)] on the existing where T : struct overloads so non-nullable and nullable value types keep dispatching unambiguously alongside the unconstrained T overloads.

Refs #129

Why

The previous where T : class static overloads accepted IObservable<T?> while typing onNext and observer as non-nullable Action<T> and IObserver<T>, forwarding values through value => onNext(value!) and (IObserver<T?>)observer. Calling LinqExtensions.SubscribeSafe or SubscribeSafeWitness.Subscribe statically on a nullable reference sequence suppressed CS8602, CS8620, and CS8622 at compile time, allocated an extra closure per subscription, and passed null into non-nullable handlers at runtime.

Breaking changes

None

How this was verified

Built ReactiveUI.Primitives.slnf and ReactiveUI.Primitives.Uno.slnf across all target frameworks, ran detect-duplicates against main, ran the full test suite with Cobertura coverage, and added Roslyn consumer compilation tests verifying clean nullable/non-nullable dispatch as well as CS8602, CS8620, and CS8622 warnings when handlers reject null.

Notes for the reviewer

  • Start with SignalOperatorParityMixins.RxNames.SubscribeSafe.cs and SubscribeSafeWitness.cs.
  • Relaxing where T : class to unconstrained T preserves the exact CLR metadata signature (IObservable<!0>, Action<!0> / IObserver<!0>, bool[]) for compiled callers while restoring [Nullable(2)] on T for C# source callers.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

…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

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (83f7c8d) to head (ea4b6ff).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit a5f736e into main Nov 21, 2026
18 checks passed
@glennawatson
glennawatson deleted the fix/subscribe-safe-static-nullability branch November 21, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant