-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersQuestionResolution-AnsweredThe question has been answeredThe question has been answered
Description
Version Used:
c# 7.3
Steps to Reproduce:
public ref struct Matrix<T> where T: unmanaged
{
private readonly int w;
private readonly int h;
private readonly Span<T> span;
public Matrix(int w, int h)
{
this.w = w;
this.h = h;
this.span = stackalloc T[w*h];
}
results in error
CS8353: A result of a stackalloc expression of type 'Span<T>' cannot be used in this context because it may be exposed outside of the containing method
I think I understand the error message and why it is necessary to prevent it.
But in this specific case the this.span is a field on a ref struct itself, so the stack will be maintained and the matrix itself cannot "be exposed outside the context".
Metadata
Metadata
Assignees
Labels
Area-CompilersQuestionResolution-AnsweredThe question has been answeredThe question has been answered