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 – Invalid type constraint resolution on ILookup #18334

Open
xperiandri opened this issue Feb 22, 2025 · 0 comments
Open

Nullness issue – Invalid type constraint resolution on ILookup #18334

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

Comments

@xperiandri
Copy link
Contributor

open System
open System.Collections.Generic
open System.Linq

module Extensions =

    type ILookup<'Key, 'Value when 'Key : not null> with

        static member Empty = Seq.empty<KeyValuePair<'Key, 'Value>>.ToLookup(_.Key, _.Value)

        member lookup.RemoveKey (key : 'Key) =
            lookup
            |> Seq.where (fun g -> 'Key.Equals(g.Key, key))
            |> Seq.collect (fun g -> g |> Seq.map (fun v -> KeyValuePair(g.Key, v)))
            |> _.ToLookup(_.Key, _.Value)

displays:

  • error FS0957: One or more of the declared type parameters for this type extension have a missing or wrong type constraint not matching the original type constraints on 'ILookup<_,_>'
  • error FS0340: The signature and implementation are not compatible because the declaration of the type parameter 'Key' requires a constraint of the form 'Key: not null
    while the required type constraint is present

Repro steps

use the uploaded class library project
WrongNonNullConditionRepro.zip

Expected behavior

No error

Actual behavior

  • error FS0957: One or more of the declared type parameters for this type extension have a missing or wrong type constraint not matching the original type constraints on 'ILookup<_,_>'
  • error FS0340: The signature and implementation are not compatible because the declaration of the type parameter 'Key' requires a constraint of the form 'Key: not null

Known workarounds

No

Related information

Provide any related information (optional):

  • .NET 8
  • Visual Studio 2022 17.13.1
@github-actions github-actions bot added this to the Backlog milestone Feb 22, 2025
@abonie abonie added Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Area-Nullness Issues related to handling of Nullable Reference Types and removed Needs-Triage labels Feb 24, 2025
@xperiandri xperiandri changed the title Nullness issue – invalid type constraint resolution on ILookup Nullness issue – Invalid type constraint resolution on ILookup Mar 2, 2025
@T-Gro T-Gro modified the milestones: Backlog, March 2025 Mar 11, 2025
@T-Gro T-Gro removed this from the March 2025 milestone Apr 1, 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-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
Status: New
Development

No branches or pull requests

3 participants