-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-IDEBugResolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implemented
Milestone
Description
Version Used: VS 2019 preview 16.7
Steps to Reproduce:
Add the following method to a class.
private static void BadSuggestion()
{
var span = (stackalloc byte[8]);
for(int i = 0; i < span.Length; i++)
{
span[i] = (byte)0xFF;
}
}Visual studio recommends removing the redundant parenthesis in the line var span = (stackalloc byte[8]);. However doing so leads to the following errors
error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
error CS1061: 'byte*' does not contain a definition for 'Length' and no accessible extension method 'Length' accepting a first argument of type 'byte*' could be found (are you missing a using directive or an assembly reference?)
error CS0214: Pointers and fixed size buffers may only be used in an unsafe context
Expected Behavior:
VS would not suggest to remove the parenthesis.
As an aside, perhaps the issue is that
static unsafe void Foo()
{
var thisIsABytePointer = stackalloc byte[8];
var thisIsASpanOfBytes = (stackalloc byte[8]);
}Metadata
Metadata
Assignees
Labels
Area-IDEBugResolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implemented