Skip to content

Executing propr snippet inside readonly struct results in compiler error #79954

@DoctorKrolic

Description

@DoctorKrolic

Version Used:
17.14.12

Steps to Reproduce:

public readonly struct MyStruct
{
    $$
}

Execute propr snippet at $$

Expected Behavior:
No compiler error after I insert the snippet

Actual Behavior:
Inserted snippet looks like this:

public readonly struct MyStruct
{
    public required int MyProperty { get; }
}

This results in a compiler error CS9034: Required member ... must be settable

I think the best solution here is to add init setter since this is most likely what user wants:

public readonly struct MyStruct
{
    public required int MyProperty { get; init; }
}

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions