False positive CS8618 null reference type warning when using required members and [SetsRequiredMembers] in derived class #74423
Labels
4 - In Review
A fix for the issue is submitted for review.
Area-Compilers
Feature - Required Members
Required properties and fields
Milestone
Version Used:
Compiler version: '4.10.0-3.24314.14 (259e82e9)'. Language version: 12.0.
, but also reproduces onmain (11 Jun 2024)
on Sharplab.Steps to Reproduce:
Diagnostic Id:
CS8618: Non-nullable property 'String' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Expected Behavior:
No diagnostics, because the base class sets the value.
Actual Behavior:
A diagnotic on the constructor of
Derived
.Additional Information
If I remove the
: Base
fromDerived
and make it an independent class, I get the same warning. This leads me to suspect this is a case of the nullable reference type analysis not being sophisticated enough to determine I have setString
in the base constructor. I am aware that NRT analysis doesn't support every pattern under the sun and there are many ways you can 'trick' it. If this is one of those cases, I apologize - but I thought it was worth mentioning all the same.The text was updated successfully, but these errors were encountered: