-
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
Collection expressions: invalid code generated for inline array spread element #70708
Comments
Moving out as this is a fairly niche scenario. Will reconsider based on customer feedback. |
I ran into this today when trying to build a IReadOnlyCollection from an inline array + some extra data. Is this scenario understood to be broken in the way it is? If so, this really should be prevented from compiling or be fixed... currently trying to use this seemingly valid pattern is a guaranteed AVE/NRE at runtime. The contents of the inline array are accidentally being reinterpreted as a Span (first 8 bytes being the ref, next 4 being the length) which causes an immediate explosion. https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA+ABATARgLABQGADAAQY4B0ASgK4B2ALgJYC2MlAwhKwA7MAbGFADKwgG7MwMAM4BuQoQDaASXoDm9GAEEoUAIYBPABRYAlAF1CGAMykZjKLTCNS1GLygQ1GrboOGhADehKRhpJ7M4vqMMKS0AhD0AOakrAD6wPpgANaayQoEAL6KRHbYpJykIQTh5FhY1aF14dFQpPp6RqQAvKRaAO5uHl4+mjpdJmaFLeGdAUrEFr2kODOzHZNKOMt9WOuzzbMJSclKyzKeMPoAJitKlJTzRhYHLdz0MhBClADytIxKAB1KDMWIAGXGxkusFu0yOpBKxSAA=== The workaround is to cast the inline array to a span directly before using the spread operator e.g |
Also ran into this myself today. This seems to sometimes cause the CLR to crash and sometimes it just silently fails without the content being added to the list. |
One more report at dotnet/runtime#107018 |
Version Used:
Steps to Reproduce:
Compile and run:
Actual Behavior:
Exception thrown at runtime iterating spread.
The text was updated successfully, but these errors were encountered: