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
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 nullwhile 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 nullKnown workarounds
No
Related information
Provide any related information (optional):