Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref safety errors reported for deconstruction assignment with discard #65522

Closed
cston opened this issue Nov 19, 2022 · 1 comment · Fixed by #65693
Closed

Ref safety errors reported for deconstruction assignment with discard #65522

cston opened this issue Nov 19, 2022 · 1 comment · Fixed by #65693
Assignees
Milestone

Comments

@cston
Copy link
Member

cston commented Nov 19, 2022

Compile with VS 17.4.0 / csc 4.4.0-3.22518.13 (7856a68):

using System;
class Program
{
    static void F1()
    {
        Span<int> s1 = stackalloc int[10];
        s1.Deconstruct(out s1, out _); // ok
    }
    static void F2()
    {
        Span<int> s2 = stackalloc int[10];
        (s2, _) = s2; // errors
    }
}
static class Extensions
{
    public static void Deconstruct(this Span<int> self, out Span<int> x, out Span<int> y)
    {
        throw null;
    }
}

Expected Behavior:
No errors

Actual Behavior:
(12,9): error CS8352: Cannot use variable '(s2, _) = s2' in this context because it may expose referenced variables outside of their declaration scope
(12,19): error CS8350: This combination of arguments to 'Extensions.Deconstruct(Span, out Span, out Span)' is disallowed because it may expose variables referenced by parameter 'self' outside of their declaration scope

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 19, 2022
@jaredpar jaredpar added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 29, 2022
@jaredpar jaredpar added this to the 17.5 milestone Nov 29, 2022
@jaredpar
Copy link
Member

@RikkiGibson on the surface looks pretty similar to #64784

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants