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
privateunsaferefstructMyRefStruct{privatereadonlyBinaryWriterwriter;privateintbufferLength;// we are in a ref struct so this never goes on the heapprivatefixedbytebuffer[255];privatevoidDump(){
Debug.Assert(bufferLength is>0 and <= 255);
writer.Write((byte)bufferLength);// CS1666: You cannot use fixed size buffers contained in unfixed expressions.//writer.Write(new ReadOnlySpan<byte>(buffer, bufferLength));// However, this works without a fixed context, even in a non-ref structfor(inti=0;i<bufferLength;i++)
writer.Write(buffer[i]);bufferLength=0;}// other members here}
Expected Behavior:
Being in a ref struct, the fixed buffer never gets relocated so creating the span should work.
The compiler is operating to the language spec today. We need to change the language design first before we can change the compiler to take advantage of this behavior.
Reproduction:
Expected Behavior:
Being in a
ref struct
, the fixed buffer never gets relocated so creating the span should work.Remark:
Maybe related: #39632
The text was updated successfully, but these errors were encountered: