Skip to content

Missing nullability warnings about member initialization in constructors in structs with default struct ctor calls #48574

Closed
@TessenR

Description

@TessenR

Version Used:

Branch master (13 Oct 2020)
Latest commit 941dc7e by Shimmy:
Default constructor suggestion between members (#48318) (#48503)

Steps to Reproduce:

Compile and run the following code

#nullable enable

new S(1);

struct S
{
  string f;
  public S(long x) : this() => f.ToString();
}

Expected Behavior:
warning CS8602: Dereference of a possibly null reference. for f.ToString()

Actual Behavior:
No nullability warnings. The code crashes at runtime with a NullReferenceException

Notes
Roslyn seems to think that : this() constructor call in struct correctly initializes all struct fields which it doesn't. Roslyn should just ignore default stuct constructor calls when enforcing nullability contract of a constructor.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions