Skip to content

Unexpected ref safety error for a prefix user-defined increment operator #78964

@AlekseyTs

Description

@AlekseyTs
public ref struct C
{
    public C M1(C c, scoped C c1)
    {
        c = c1++; // error CS8352: Cannot use variable 'scoped C c1' in this context because it may expose referenced variables outside of their declaration scope
        return c;
    }

    public C M2(C c, scoped C c2)
    {
        c = ++c2; // Unexpected error CS8352: Cannot use variable 'scoped C c2' in this context because it may expose referenced variables outside of their declaration scope
        return c;
    }
    
    public static C operator ++(scoped C left) => throw null;
}

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions