Skip to content

Meaningless nullability warning is reported for deconstruction #72913

@AlekseyTs

Description

@AlekseyTs
        [Fact]
        public void Test()
        {
            string source = @"
#nullable enable

public class C
{
    public static void Main()
    {
        var c = new C();
        var a = (c[1], _) = new C2();
    }

    int _test1 = 0;    
    dynamic this[int x]
    {
        get => _test1;
        set => _test1 = value;
    }
}

class C2
{
    public void Deconstruct(out int x, out int y)
    {
        (x, y) = (2, 123);
    }
}
";

            var comp = CreateCompilation(source, options: TestOptions.DebugExe, targetFramework: TargetFramework.StandardAndCSharp);

            comp.VerifyDiagnostics(
                // (9,18): warning CS8624: Argument of type 'dynamic' cannot be used as an output of type 'int' for parameter 'x' in 'void C2.Deconstruct(out int x, out int y)' due to differences in the nullability of reference types.
                //         var a = (c[1], _) = new C2();
                Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgumentForOutput, "c[1]").WithArguments("dynamic", "int", "x", "void C2.Deconstruct(out int x, out int y)").WithLocation(9, 18)
                );
        }

There is no argument of type dynamic. And there is no nullability difference between int and dynamic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions