-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Regression from first-class spans with overload picking #76443
Comments
Forcing the call to use the |
If this is intended as a breaking change, that’s fine with me (I’ve already fixed the code). It just isn’t documented as one. |
This is an expected breaking change. ReadOnlySpan is now preferred over Span to avoid ArrayTypeMismatchExceptions that would occur at runtime if you used covariant arrays.
That PR doesn't fix it, it makes it broader in fact, per LDM discussion linked above.
I will open a PR to document the break, thanks. |
@jjonescz why is the rule applied to all arrays, and not just those that could possibly be covariant? Converting from |
That wasn't discussed but I suspect the LDT wouldn't be in favor of complicating the rules like that. |
This change unfortunately also seems to break the following scenario, at least it does on byte[] bytes = new byte[24];
ref SomeStruct bytesAsStruct = ref MemoryMarshal.AsRef<SomeStruct>(bytes); Now if you need a writable
Neither of which are as nice as it used to be. |
@jjonescz would you be supportive of bringing this additional covariance support to LDM, with motivating examples such as this one? It just feels wrong to me to have |
That is a very similar scenario to the one in the issue description, and the mitigation is also the same - add ref S bytesAsStruct = ref MemoryMarshal.AsRef<S>(bytes.AsSpan()); |
Array covariance was the original reason, but now after LDM discussion the rule is even broader - it doesn't apply to just arrays anymore but to anything that's convertible to ReadOnlySpan or Span - dotnet/csharplang#8779. The motivation was to simplify the rules:
But it also says "We don't think we have enough data to make such a decision today. We don't know of any APIs that this would negatively affect, but more investigation needs to be done before making a call." so I guess these MemoryMarhsal APIs are the data. I will ask around. |
Yeah, as I've noted myself. I'm simply pointing out its less intuitive than it used to be, making first-class support to be a second-class in some cases haha. Not trying to discard any work in this matter, I'll be happy if those particular cases mentioned are considered once more. |
This argument would imply that say Limiting it to only types which are known to be |
Version Used: 9.0.200.preview
Steps to Reproduce:
MemoryMarshal.Cast
with an arraySpan<T>
overload, but getReadOnlySpan<T>
overloadhttps://sharplab.io/#v2:EYLgtghglgdgNAExAagD4AEBMBGAsAKHQAYACdbAOgCUBXGAFyjAFMKBJB5gJwHsAHAMrcAblADGzAM4BuAgXQBmMphIBhADYRJkggG8CJQ2SXoALCQCyzegAseCABQBKA0f34jnkgh41g65gBtAF0Segh/ZhIAXhIYGnV1AEJZDy9DAT4IGAAeBJ4YAHMAPm8pehjLZjAeLgBPCwguSRsIdQpVLXocnz8AuBJ8ouKHcMinVM8AXwIpoA===
Diagnostic Id:
Expected Behavior:
The
Span<T>
overload is used, as it was on .NET 8 and .NET 9 RC2.Actual Behavior:
The
ReadOnlySpan<T>
overload is used instead.The text was updated successfully, but these errors were encountered: