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 returns/locals: Encapsulate Field - encapsulating fields used as ref returns causes attempt to illegally return ref property #8444

Closed
dpoeschl opened this issue Feb 6, 2016 · 1 comment

Comments

@dpoeschl
Copy link
Contributor

dpoeschl commented Feb 6, 2016

Encapsulate field on x (either via the command or with the "and use property" variation) in

class Program
{
    int x;

    public ref int M()
    {
        return ref x;
    }
}

Expected: Only update references to reference the property where it is valid to do so. Maybe there's a use for "Encapsulate Field to ref-returning property", but right now I doubt that will be a common enough pattern to offer every time someone wants to encapsulate a field.

class Program
{
    int x;

    public int X
    {
        get
        {
            return x;
        }

        set
        {
            x = value;
        }
    }

    public ref int M()
    {
        return ref x; // Still referencing field
    }
}

Actual: ref references to the field are updated to use the property, which is illegal (without making the property ref-returning).

class Program
{
    int x;

    public int X
    {
        get
        {
            return x;
        }

        set
        {
            x = value;
        }
    }

    public ref int M()
    {
        return ref X; // CS 8910
    }
}
@CyrusNajmabadi
Copy link
Member

Closing out due to lacak of feedback.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2024
@dotnet dotnet locked as resolved and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants