Skip to content

Confirm that we want to report hidden HDN_NullCheckIsProbablyAlwaysFalse diagnostics #29868

@AlekseyTs

Description

@AlekseyTs
        [Fact]
        public void ConditionalBranching_IsConstantPattern_Null_AlreadyTestedAsNonNull()
        {
            // PROTOTYPE(NullableReferenceTypes): confirm that we want such hidden warnings
            CSharpCompilation c = CreateCompilation(new[] { @"
class C
{
    void Test(object? x)
    {
        if (x != null)
        {
            if (x is null) // hidden
            {
                x.ToString(); // warn
            }
            else
            {
                x.ToString();
            }
        }
    }
}
", NonNullTypesTrue, NonNullTypesAttributesDefinition });

            c.VerifyDiagnostics(
                // (8,22): hidden CS8606: Result of the comparison is possibly always false.
                //             if (x is null) // hidden
                Diagnostic(ErrorCode.HDN_NullCheckIsProbablyAlwaysFalse, "null").WithLocation(8, 22),
                // (10,17): warning CS8602: Possible dereference of a null reference.
                //                 x.ToString(); // warn
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(10, 17)
                );
        }

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