Skip to content

Unexpected conversion error for a deconstruction involving dynamic type #72914

@AlekseyTs

Description

@AlekseyTs
        [Fact]
        public void Test()
        {
            string source = @"
public class C
{
    public static void Main()
    {
        (int a, _) = new C2();
        new C2().Deconstruct(out dynamic d, out _);
        int b = d;
        (int e, _) = (d, 124);
    }
}

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

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

            comp.VerifyDiagnostics(
                // (6,10): error CS0266: Cannot implicitly convert type 'dynamic' to 'int'. An explicit conversion exists (are you missing a cast?)
                //         (int a, _) = new C2();
                Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "int a").WithArguments("dynamic", "int").WithLocation(6, 10)
                );
        }

The implicit conversion exists, which can be observed on the following lines (no errors for them), and one of them is also a deconstruction (from a tuple):

        int b = d;
        (int e, _) = (d, 124);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions