Skip to content

IDE0370 false positive, when initializing auto-property with null!. #81843

@PetSerAl

Description

@PetSerAl

Version Used:
Locally: SDK 10.0.101
lab.razor.fyi: 5.0.0 and 5.3.0-2.25619.2

Steps to Reproduce:

class C
{
    public C() { }
    public string S { get; set; } = null!; //IDE0370: Suppression is unnecessary 
}

https://lab.razor.fyi/#42pi5OIKKMpPL0rM1UsuFipJzkksLlZw5uWq5uVSUFBQKChNyslMVnDW0FSoVqhFESsuKcrMS1cIVqhWSE8tsVYoBhG1CrYKeaU5OYrWCvr6ni6uBsbmBlYKwaUFBUWpxcWZ-XkKmcUKpXl5qcmpxcWJRZUKvFy1XmypRUX5RcVRnBxvfpw5-SFNgCWBsYIRAA

20260103-1611-05.8100910.mp4

IDE0370 on ! sign.

Diagnostic Id:
IDE0370: Suppression is unnecessary

Expected Behavior:
No diagnostic should be produced, as null assigned to not nullable property.

Actual Behavior:
False positive IDE0370. When proposed fix applied, it result in "CS8625: Cannot convert null literal to non-nullable reference type." warning.
No diagnostic, if constructor removed/commented.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions