Repository navigation
Closed
Labels
Area-NullnessIssues related to handling of Nullable Reference TypesBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone
Description
Issue description
Publishing an event produces nullness warning
See EventNullabilityMismatch.fs
WrongNonNullConditionRepro.zip
Choose one or more from the following categories of impact
- Unexpected nullness warning (false positive in nullness checking, code uses --checknulls and langversion:preview).
- Missing nullness warning in a case which can produce nulls (false negative, code uses --checknulls and langversion:preview).
- Breaking change related to older
nullconstructs in code not using the checknulls switch. - Breaking change related to generic code and explicit type constraints (
null,not null). - Type inference issue (i.e. code worked without type annotations before, and applying the --checknulls enforces type annotations).
- C#/F# interop issue related to nullness metadata.
- Other (none of the categories above apply).
Operating System
Windows (Default)
What .NET runtime/SDK kind are you seeing the issue on
.NET SDK (.NET Core, .NET 5+)
.NET Runtime/SDK version
9.0.200
Reproducible code snippet and actual behavior
open System
open System.Windows.Input
/// A command that optionally hooks into CommandManager.RequerySuggested to
/// automatically trigger CanExecuteChanged whenever the CommandManager detects
/// conditions that might change the output of canExecute. It's necessary to use
/// this feature for command bindings where the CommandParameter is bound to
/// another UI control (e.g. a ListView.SelectedItem).
type internal Command(execute, canExecute) =
let canExecuteChanged = Event<EventHandler, EventArgs>()
// CommandManager only keeps a weak reference to the event handler,
// so a strong reference must be maintained,
// which is achieved by this mutable let-binding.
// Can test this via the UiBoundCmdParam sample.
let mutable _handler = null
member this.AddRequeryHandler () =
let handler = EventHandler(fun _ _ -> this.RaiseCanExecuteChanged())
_handler <- handler
member this.RaiseCanExecuteChanged () = canExecuteChanged.Trigger(this, EventArgs.Empty)
interface ICommand with
[<CLIEvent>]
member _.CanExecuteChanged = canExecuteChanged.Publish
member _.CanExecute p = canExecute p
member _.Execute p = execute pPossible workarounds
No response
Metadata
Metadata
Assignees
Labels
Area-NullnessIssues related to handling of Nullable Reference TypesBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.
Type
Projects
- StatusShow more project fieldsNew

Activity
[-]Nullness issue –[/-][+]Nullness issue – Publishing an event produces nullness warning[/+]Add ICommand CanExecuteChanged CLIEvent nullness test
Add 'not null' constraints to event delegate type parameters
Fix FS3261 nullness warning for CLIEvent interface implementations
Add delegate-specific pattern matches to skip nullness checking