Skip to content

Open question for semi-auto properties #5563

@Youssef1313

Description

@Youssef1313

Should semi-auto properties be treated as auto properties for the purpose of definite assignment?

struct Program
{
    // causes CS0843:
    // Auto-implemented property must be fully assigned before control is returned to the caller.
    int P1 { get; set; }

    int P2 { get => field; set => field = value; } // CS0843?
    int P3 { get => field; set; } // CS0843?
    int P4 { get; set => field = value; } // CS0843?
    

    public Program(int dummy)
    {
    }
}

There is also this scenario:

struct Program
{
    struct S1
    {
        public int AutoProp { get; }
        public int SemiAutoProp { get => field; }
        public int ManualProp { get => throw null; }
    }

    S1 x { get; set; }
    S1 x2 { get; set; }
    S1 x3 { get; set; }

    public Program(int dummy) // Error that x must be assigned, no error on x3. What should x2 do?
    {
        _ = x.AutoProp;
        _ = x2.SemiAutoProp;
        _ = x3.ManualProp;
    }
}

The above scenario is a bit related to https://sharplab.io/#v2:EYLgtghglgdgNAFxANwKYCcoDMCeAfAZwXQFcBjBAAgAEBGAdgFgAoAbxcs8qNIsoGVaHLu2ZdxNAMyVYVAAq1KrSgHNUCANyUAvsIlSZMeQCYlq9ZQC8APkoAGLbrFcnegYoAeZtZu7qNrs6c1NJ09AAUspQAJiRgYDgAlG6i+pwA9OmUAEQAwvx2ABwALJIglACCJAgA9gC0UGAADgA2qGCoRqjRlE3oNU0YCDiUAORhAHQeo5RgJERu4pmUwKiUWCQtLSMQBARQKjDdK6hYNehrZDVG/S0yBDT0x7WLXMsIABaXEFsYE9n3SjXbbcD41ADuMBkWEonzWZy2ENgKkoLVgaygDyu8U6CG6E1ewVoEzoAE5wh4JnJjIkNITKMsAHI1PGwj4QKjUOyUBSGIioCA9Gow6mUcFQLaUH7giA4B4EMHgyj5IqlenLC4qCDoaJtPZir5w9BstZoo6A7EdLrRAlBHQsFjaIA===

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions