Skip to content

Ref field initializer is treated as a value assignment #64725

@cston

Description

@cston

Compile:

ref struct R
{
    ref int _f = 1;

    public R() { }
}

Expected:

error CS8172: Cannot initialize a by-reference variable with a value

Actual:
Code compiles and generated code assigns the value 1 to the null location in _f.

See related #64720.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions