Add suggested stackalloc initializer tests#25656
Conversation
|
/cc @VSadov for review. |
| var expressions = tree.GetCompilationUnitRoot().DescendantNodes().OfType<ImplicitStackAllocArrayCreationExpressionSyntax>().ToArray(); | ||
| Assert.Equal(3, expressions.Length); | ||
|
|
||
| var @stackalloc = expressions[0]; |
There was a problem hiding this comment.
@stackalloc [](start = 16, length = 11)
Nit: I'd recommend asserting the syntax, so it's unambiguous what we're looking at:
Assert.Equal("...", @stackalloc.ToString());
| }", TestOptions.UnsafeReleaseDll).VerifyDiagnostics( | ||
| // (9,13): error CS8353: A result of a stackalloc expression of type 'Span<double>' cannot be used in this context because it may be exposed outside of the containing method | ||
| // _ = stackalloc double[2] { 1, 1.2 }; | ||
| Diagnostic(ErrorCode.ERR_EscapeStackAlloc, "stackalloc double[2] { 1, 1.2 }").WithArguments("System.Span<double>").WithLocation(9, 13) |
There was a problem hiding this comment.
I didn't understand this error. I would have expected this to work (nothing is escaping the scope of the method). Is there a bug with escape scope of discards?
@VSadov Can you confirm and file a bug as appropriate?
There was a problem hiding this comment.
looks like discard symbols are considered as returnable so we cant assign stackalloc with local lifetime.
There was a problem hiding this comment.
"Returnable" is much more common, so it makes sense to treat _ as returnable.
If they are considered not returnable, the cases like following would be errors:
return Method(out _ ); // what if Method returns its argument ?
Method(out _ , ref returnable); // what if Method assigns one argument to another ?
jcouv
left a comment
There was a problem hiding this comment.
LGTM to me with one question on discard scenario.
Thanks!
|
@VSadov for review (more tests for stackalloc init feature). Thanks |
|
@dotnet-bot test windows_coreclr_release_prtest please |
|
Merged. Thanks @alrz! |
* dotnet/dev15.7.x: Foreach to For refactoring (dotnet#25460) added more logging for completion to track some test failures where completion doesn't show up when it should have. (dotnet#25801) Add suggested stackalloc initializer tests (dotnet#25656) Addressed PR feedback. [SQLite] Fix continuous probing for sqlite Add missing file, update test for clearer output. Addressed PR feedback, updated ILocalFunctionOperation to final design specified in review. Added both ExpressionBody and BlockBody to the underlying BoundNode for local functions, and exposed both to IOperation consumers. Update PATH to our xcopy CLI
Add tests from feature review (see #25160)