Skip to content

Inferred variable initializer should attempt to resolve extension before trying to infer natural function type #79309

@jcouv

Description

@jcouv

Reported in dotnet/csharplang#9517 by @LeQuackers
Needs to be confirmed with WG, but if resolving extensions yields something other than a method, then we should be done (no need to infer natural function type).

    [Fact]
    public void TODO2()
    {
        var src = """

public static class Extensions
{
    extension(C c)
    {
        public int M => C.M();
    }
}

public class Test
{
    public static void Foo()
    {
        var upper = new C().M; // error CS8917: The delegate type could not be inferred.
    }
}

public class C
{
    public static int M() => 0;
}
""";
        var comp = CreateCompilation(src);
        comp.VerifyEmitDiagnostics(
            // (14,21): error CS8917: The delegate type could not be inferred.
            //         var upper = new C().M; // error CS8917: The delegate type could not be inferred.
            Diagnostic(ErrorCode.ERR_CannotInferDelegateType, "new C().M").WithLocation(14, 21));
    }

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions