-
Notifications
You must be signed in to change notification settings - Fork 825
Labels
Area-Compiler-ImportAndInteropimport of .NET DLLs and interopimport of .NET DLLs and interopArea-NullnessIssues related to handling of Nullable Reference TypesIssues related to handling of Nullable Reference TypesBug
Milestone
Description
let t1 = "" :> IEquatable<string>
// Nullness warning: A non-nullable 'string' was expected but this expression is nullable. Consider either changing the target to also be nullable, or use pattern matching to safely handle the null case of this expression.
VS 17.14.6
Misc notes:
- The IEquatable interface unfortunately marks arguments to
Equals
as nullable generic mathematics interfaces should use nullable reference types runtime#73855 (comment), a wart which F# seems to squash, allowingIEquatable<'T>
to be defined withEquals(y: 'T) = ...
. But that doesn't seem directly relevant to the above issue. "" :> IEquatable<string | null>
doesn't give a warning- A workaround is to define a wrapper
[<Struct>] type StringWrapper(s: string) = member _.Value = s
. - This applies to types where null is "allowed":
[<AllowNullLiteral>]
type NullAllowed() =
interface IEquatable<NullAllowed> with member _.Equals(y: NullAllowed) = true
let _ = NullAllowed() :> IEquatable<NullAllowed>
// Nullness warning: The types 'IEquatable<NullStringWrapper>' and 'IEquatable<NullStringWrapper> | null' do not have compatible nullability.
brianrourkeboll and T-Gro
Metadata
Metadata
Assignees
Labels
Area-Compiler-ImportAndInteropimport of .NET DLLs and interopimport of .NET DLLs and interopArea-NullnessIssues related to handling of Nullable Reference TypesIssues related to handling of Nullable Reference TypesBug
Type
Projects
Status
New