Bugfix :: Nullness :: Eliminate spurious warnings when working with CLI events#19221
Merged
Bugfix :: Nullness :: Eliminate spurious warnings when working with CLI events#19221
Conversation
…sue #18361) This test reproduces the FS3261 nullness warning that occurs when implementing INotifyPropertyChanged interface with F# Event and [<CLIEvent>] attribute. The test documents the current buggy behavior: - INotifyPropertyChanged with PropertyChangedEventHandler produces spurious FS3261 - F#-defined interfaces with EventHandler do not produce the warning When the bug is fixed, the test should be updated to use shouldSucceed instead.
Add 'not null' constraints to the delegate type parameters in: - IDelegateEvent<'Delegate> - IEvent<'Delegate,'Args> - DelegateEvent<'Delegate> - Event<'Delegate,'Args> These constraints are guarded with #if BUILDING_WITH_LKG || BUILD_FROM_SOURCE to ensure bootstrap compatibility with the LKG compiler. This change is part of the fix for nullness warnings with CLIEvent properties (#18361, #18349). While these constraints alone don't fix the FS3261 warning, they are the correct FSharp.Core changes needed for proper nullness support. A compiler-side fix is also needed to fully resolve the issue.
Suppress spurious nullness warnings (FS3261) when implementing interfaces like INotifyPropertyChanged or ICommand using F# Events with --checknulls enabled. The fix has three parts: 1. ConstraintSolver.fs: Suppress delegate nullness warnings in SolveNullnessEquiv and SolveNullnessSubsumesNullness when both types are delegates (same type, different nullness) 2. infos.fs: Strip nullness from delegate type in FindDelegateTypeOfPropertyEvent 3. FSharp.Core: Add 'not null' constraint to DelegateEvent and Event types The warning was spurious because: - C# interfaces like INotifyPropertyChanged lack nullable annotations (predate NRT) - F# treats unannotated C# parameters as nullable - F#'s event AddHandler expects non-null delegates - In practice, event handlers are never null Fixes #18361 Fixes #18349
Subtask 2: Study how byref types are handled specially in SolveTypeSubsumesType (lines 1562-1573) to understand the correct pattern for adding delegate-specific handling. Key findings documented: - Pattern match guard structure: tyconRefEq + type-specific check - Nullness is intentionally skipped by omitting SolveNullnessSubsumesNullness call - Byref case precedes generic TType_app case in pattern match order - Template for delegate-specific handling following same pattern
…ssSubsumesNullness Remove the isDelegateTy checks and suppressDelegateWarning logic from the generic nullness-solving functions. This was a hack that polluted low-level type unification with domain-specific exceptions. The proper fix will be added at the correct abstraction level in SolveTypeEqualsType and SolveTypeSubsumesType following the byref pattern.
Following the byref special handling pattern (Option B from VISION.md), add TType_app pattern matches for delegate types in SolveTypeEqualsType and SolveTypeSubsumesType that skip nullness checking. This is the proper architectural approach - handling delegate types at the correct abstraction level rather than in low-level nullness functions. Fixes #18361 Fixes #18349
Contributor
❗ Release notes required
|
abonie
approved these changes
Jan 19, 2026
Member
Author
|
/azp-run |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
This was referenced Jan 19, 2026
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.
Fix FS3261 nullness warning when implementing INotifyPropertyChanged or ICommand CLIEvent properties. (Issue #18361, Issue #18349)
Fixes #18361
Fixes #18349