Skip to content

Unexpected WRN_ConvertingNullableToNonNullable/WRN_NullReferenceReceiver after explicit null check for "dynamic?" value. #30939

@AlekseyTs

Description

@AlekseyTs
        [Fact]
        public void Test()
        {
            var source = @"
class Outer
{
    void M1(dynamic? x1)
    {
        if (x1 == null) return;
        Outer y = x1;
        x1.ToString();
    }
}
";

            CreateCompilation(source, options: WithNonNullTypesTrue()).VerifyDiagnostics(
                // (7,19): warning CS8600: Converting null literal or possible null value to non-nullable type.
                //         Outer y = x1;
                Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "x1").WithLocation(7, 19),
                // (8,9): warning CS8602: Possible dereference of a null reference.
                //         x1.ToString();
                Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x1").WithLocation(8, 9)
                );
        }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions