Skip to content

Add RP0001 Roslyn analyzer for nullable reference type support#563

Draft
runceel with Copilot wants to merge 2 commits into
mainfrom
copilot/support-nullable-reference-types
Draft

Add RP0001 Roslyn analyzer for nullable reference type support#563
runceel with Copilot wants to merge 2 commits into
mainfrom
copilot/support-nullable-reference-types

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Nullable reference types are enabled, but the compiler cannot flag the one case that produces a silent null: a ReactiveProperty-family value created for a non-nullable reference type without an initial value initializes Value to default(T) (i.e. null). Removing the historical default constructors would be a breaking change, so this is addressed with an analyzer — the approach converged on in the issue discussion.

Analyzer (RP0001, category Usage, Warning)

  • New Source/ReactiveProperty.Analyzer project (netstandard2.0) with ReactivePropertyNullableAnalyzer.
  • Flags creations where the type argument is a non-nullable reference type and no initial value is supplied:
    • new ReactiveProperty<T>(), new ReactivePropertySlim<T>(), new ReadOnlyReactivePropertySlim<T>(source)
    • source.ToReadOnlyReactivePropertySlim(), source.ToReadOnlyReactiveProperty()
  • Ignores value types, nullable T?, open type parameters, and code with the nullable context disabled.
  • For the ToReadOnly* extension methods, T is taken from the source IObservable<T> element type — the compiler infers those methods' return type as T? because of their initialValue = default parameter, so the return type can't be used.

Packaging

  • Shipped inside both ReactiveProperty.Core and ReactiveProperty packages under analyzers/dotnet/cs (referenced with ReferenceOutputAssembly="false", so it adds no runtime dependency).

Tests & docs

  • 12 MSTest cases via Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.MSTest.
  • Decision recorded in ADR 0006.
#nullable enable
var a = new ReactiveProperty<string>();               // RP0001
var b = new ReactivePropertySlim<string>();           // RP0001
var c = source.ToReadOnlyReactivePropertySlim();      // RP0001

var d = new ReactivePropertySlim<string>("initial");  // ok — initial value
var e = new ReactivePropertySlim<string?>();          // ok — nullable T
var f = new ReactivePropertySlim<int>();              // ok — value type

Out of scope

The ReactiveProperty (NETStandard) assembly has 91 pre-existing internal nullable warnings unrelated to this change; resolving them would touch public API nullability annotations (potentially breaking) and is left as separate follow-up work.

Copilot AI linked an issue Jul 8, 2026 that may be closed by this pull request
6 tasks
Copilot AI changed the title [WIP] Support for nullable reference types Add RP0001 Roslyn analyzer for nullable reference type support Jul 8, 2026
Copilot AI requested a review from runceel July 8, 2026 08:35
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.

Support for nullable reference types

2 participants