Skip to content

new T does not handle nullable property setters. #33387

@333fred

Description

@333fred
        [Fact]
        public void New_04()
        {
            var source = @"
class C
{
    object Prop { get; set; }
    void M<T>() where T : C, new()
    {
        var c = new T() { Prop = null }; // 1
        _ = c.Prop.ToString(); // 2
    }
}";

            var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
            comp.VerifyDiagnostics();
        }

Currently, no warnings are reported, because we're not handling the object initializer for BoundNewT nodes.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions