Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullness issue – Publishing an event produces nullness warning #18349

Open
1 of 7 tasks
xperiandri opened this issue Mar 1, 2025 · 0 comments
Open
1 of 7 tasks

Nullness issue – Publishing an event produces nullness warning #18349

xperiandri opened this issue Mar 1, 2025 · 0 comments
Assignees
Labels
Area-Nullness Issues related to handling of Nullable Reference Types Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@xperiandri
Copy link
Contributor

Issue description

Publishing an event produces nullness warning

Image

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 null constructs 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 p

Possible workarounds

No response

@xperiandri xperiandri added Area-Nullness Issues related to handling of Nullable Reference Types Bug Needs-Triage labels Mar 1, 2025
@github-actions github-actions bot added this to the Backlog milestone Mar 1, 2025
@xperiandri xperiandri changed the title Nullness issue – Nullness issue – Publishing an event produces nullness warning Mar 2, 2025
@T-Gro T-Gro removed their assignment Mar 10, 2025
@T-Gro T-Gro modified the milestones: Backlog, March 2025 Mar 11, 2025
@T-Gro T-Gro self-assigned this Mar 11, 2025
@abonie abonie added Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. and removed Needs-Triage labels Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Nullness Issues related to handling of Nullable Reference Types Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Status: New
Development

No branches or pull requests

3 participants