Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InterfaceMap returns non-GenericMethodDefinition for static abstract interface generic methods on the target type #74132

Closed
mburbea opened this issue Aug 18, 2022 · 4 comments
Assignees
Milestone

Comments

@mburbea
Copy link

mburbea commented Aug 18, 2022

Description

InterfaceMap when mapping static abstract generic methods does not return a generic method definition. The generic arguments are also generic method type parameters, but they are the ones for the interface type.

Reproduction Steps

public interface I<T> where T : I<T>
{
    public void Instance<M>(M m);
    public static abstract void Static<M>(M m);
}

public readonly struct C : I<C>
{
    public void Instance<M>(M m) { }
    public static void Static<M>(M m) { }
}

internal class Program
{
    static void Main(string[] args)
    {
        var interfaceMap = typeof(C).GetInterfaceMap(typeof(I<C>));
        for (int i = 0; i < interfaceMap.InterfaceMethods.Length; i++)
        {
            var imethod = interfaceMap.InterfaceMethods[i];
            var tmethod = interfaceMap.TargetMethods[i];
            Console.WriteLine($"Interface.{imethod.Name} is generic method def: {imethod.IsGenericMethodDefinition}");
            Console.WriteLine($"Target.{tmethod.Name} is generic method def: {tmethod.IsGenericMethodDefinition}");
        }
        
        Console.Read();
    }
}

Expected behavior

Interface.Instance is generic method def: True
Target.Instance is generic method def: True
Interface.Static is generic method def: True
Target.Static is generic method def: True

Actual behavior

Interface.Instance is generic method def: True
Target.Instance is generic method def: True
Interface.Static is generic method def: True
Target.Static is generic method def: False

Regression?

No as these are new.

Known Workarounds

No response

Configuration

.net 7 preview 7.

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 18, 2022
@MichalStrehovsky
Copy link
Member

Cc @trylek @davidwrighton

@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Aug 18, 2022
@mangod9 mangod9 added this to the 8.0.0 milestone Aug 18, 2022
@mangod9
Copy link
Member

mangod9 commented Aug 22, 2023

@trylek can you take a look at this issue if this is required for 8?

@jkotas
Copy link
Member

jkotas commented Aug 23, 2023

We have number of issues in GetInterfaceMap for static interface methods. See #90518 and the issues that it is linked to.

trylek added a commit to trylek/runtime that referenced this issue Aug 23, 2023
I have verified locally that the problem described in the issue
no longer exists in .NET 8 RC1, the bug was probably fixed earlier
this year by David Wrighton. I think the regression test described
in the issue is useful so I'm proposing to merge it in; this PR
will then close the issue.

Fixes: dotnet#74132

Thanks

Tomas
@ghost ghost added in-pr There is an active PR which will close this issue when it is merged and removed in-pr There is an active PR which will close this issue when it is merged labels Aug 23, 2023
@trylek
Copy link
Member

trylek commented Aug 23, 2023

I have verified locally that this bug no longer reproes as of .NET 8 RC1, I believe it was fixed earlier this year by David Wrighton.

@trylek trylek closed this as completed Aug 23, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants