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
CS9361 (stackalloc without initializer inside SkipLocalsInit requires unsafe) only fires when the stackalloc is the direct RHS of the local initializer. Wrapping it in parentheses, a conditional, or a cast silences the diagnostic, even though the underlying behavior is identical.
Repro
[module:System.Runtime.CompilerServices.SkipLocalsInit]publicclassC{publicvoidDirect(){System.Span<char>s=stackallocchar[128];}// CS9361 ✅publicvoidParens(){System.Span<char>s=(stackallocchar[128]);}// no diagnostic ❌publicvoidTernary(boolb){System.Span<char>s=b?stackallocchar[128]:default;}// no diagnostic ❌publicvoidCast(){System.Span<char>s=(System.Span<char>)stackallocchar[128];}// no diagnostic ❌publicvoidCall(){Consume(stackallocchar[128]);}// no diagnostic ❌voidConsume(System.Span<char>span){}}
Expected
CS9361 should fire on every StackAllocArrayCreationExpressionSyntax whose result is consumed as Span<T> / ReadOnlySpan<T> under [SkipLocalsInit], regardless of intermediate conversions.
Version
Reproduced on Microsoft.CodeAnalysis.CSharp 5.8.0-1.26266.103 (dotnet/runtime live build).
Note
This issue was drafted with the help of GitHub Copilot.
unsafe-v2
CS9361 (
stackallocwithout initializer insideSkipLocalsInitrequires unsafe) only fires when thestackallocis the direct RHS of the local initializer. Wrapping it in parentheses, a conditional, or a cast silences the diagnostic, even though the underlying behavior is identical.Repro
Expected
CS9361 should fire on every
StackAllocArrayCreationExpressionSyntaxwhose result is consumed asSpan<T>/ReadOnlySpan<T>under[SkipLocalsInit], regardless of intermediate conversions.Version
Reproduced on Microsoft.CodeAnalysis.CSharp
5.8.0-1.26266.103(dotnet/runtime live build).Note
This issue was drafted with the help of GitHub Copilot.