diff --git a/src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_74132.cs b/src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_74132.cs new file mode 100644 index 0000000000000..5087e6b05c6ca --- /dev/null +++ b/src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_74132.cs @@ -0,0 +1,46 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +// This regression test tracks the issue where GetInterfaceMap returns incorrect +// non-generic entries for generic static virtual methods. + +public interface I where T : I +{ + public void Instance(M m); + public static abstract void Static(M m); +} + +public readonly struct C : I +{ + public void Instance(M m) { } + public static void Static(M m) { } +} + +internal class Program +{ + static int Main(string[] args) + { + var interfaceMap = typeof(C).GetInterfaceMap(typeof(I)); + bool allMethodsAreGeneric = true; + 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}"); + if (!imethod.IsGenericMethodDefinition || !tmethod.IsGenericMethodDefinition) + { + allMethodsAreGeneric = false; + } + } + + if (!allMethodsAreGeneric) + { + throw new Exception("Test failed, all above methods should be reported as generic!"); + } + + return 100; + } +} diff --git a/src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_74132.csproj b/src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_74132.csproj new file mode 100644 index 0000000000000..7f0c12d57d8e5 --- /dev/null +++ b/src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_74132.csproj @@ -0,0 +1,9 @@ + + + true + Exe + + + + +