You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most of our MemoryExtensions methods have a shape like:
publicstaticbool Contains<T>(thisSpan<T>span,Tvalue)where T :IEquatable<T>
where the T is constrained to be IEquatable<T>. The questionable nature of the constraint in general aside (we can use EqualityComparer<T>.Default), the constraint is too strict with regards to nullable reference types. The constraint should be where T : IEquatable<T>? rather than where T : IEquatable<T>; otherwise, it's prohibiting nullable Ts, e.g. this erroneously warns:
warning CS8631: The type 'string?' cannot be used as type parameter 'T' in the generic type or method 'MemoryExtensions.Contains<T>(Span<T>, T)'. Nullability of type argument 'string?' doesn't match constraint type 'System.IEquatable<string?>'.
We need to audit all such constraints and fix them.
Tagging subscribers to this area: @dotnet/area-system-memory
See info in area-owners.md if you want to be subscribed.
Issue Details
Most of our MemoryExtensions methods have a shape like:
publicstaticbool Contains<T>(thisSpan<T>span,Tvalue)where T :IEquatable<T>
where the T is constrained to be IEquatable<T>. The questionable nature of the constraint in general aside (I don't see a good reason to constrain to IEquatable<T> here), the constraint is too strict with regards to nullable reference types. The constraint should be where T : IEquatable<T>? rather than where T : IEquatable<T>; otherwise, it's prohibiting nullable Ts, e.g. this erroneously warns:
warning CS8631: The type 'string?' cannot be used as type parameter 'T' in the generic type or method 'MemoryExtensions.Contains<T>(Span<T>, T)'. Nullability of type argument 'string?' doesn't match constraint type 'System.IEquatable<string?>'.
We need to audit all such constraints and fix them.
Most of our MemoryExtensions methods have a shape like:
where the
T
is constrained to beIEquatable<T>
. The questionable nature of the constraint in general aside (we can useEqualityComparer<T>.Default
), the constraint is too strict with regards to nullable reference types. The constraint should bewhere T : IEquatable<T>?
rather thanwhere T : IEquatable<T>
; otherwise, it's prohibiting nullableT
s, e.g. this erroneously warns:with:
We need to audit all such constraints and fix them.
cc: @terrajobst, @bartonjs, @jeffhandley
The text was updated successfully, but these errors were encountered: