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
publicstaticvoidMakePropertyValue<T>(Tval){if(valisSpan<byte> or ReadOnlySpan<byte>){}}
Expected Behavior:
Compile !
Actual Behavior:
Error CS8121 : An expression of type 'T' cannot be handled by a pattern of type 'Span'.
Error CS8121 : An expression of type 'T' cannot be handled by a pattern of type 'ReadOnlySpan'.
The text was updated successfully, but these errors were encountered:
Your first example compiles, but doesn't work the way you want, and you get warnings about that:
warning CS0184: The given expression is never of the provided ('Span<byte>') type
This is because the is operator doesn't work for ref structs like Span<T>, see #63085.
As for why one is a warning and the other an error, I suspect this is because the is type test is an old feature that works the way it always did, but pattern matching is a new feature, so it can be stricter. Though per #63085 (comment), this might change in the future.
In effect, I think this issue can be closed as a duplicate of #63085.
Version Used:
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
C:\Program Files\dotnet\sdk\6.0.302\Roslyn\bincore\csc.dll
Steps to Reproduce:
Why this code compiles
but this code can't compiles!
Expected Behavior:
Compile !
Actual Behavior:
Error CS8121 : An expression of type 'T' cannot be handled by a pattern of type 'Span'.
Error CS8121 : An expression of type 'T' cannot be handled by a pattern of type 'ReadOnlySpan'.
The text was updated successfully, but these errors were encountered: