From 3f887ce906cf0b2a672b75d33b6cb2c181c89d49 Mon Sep 17 00:00:00 2001 From: Tomas Rylek Date: Wed, 23 Aug 2023 21:21:33 +0200 Subject: [PATCH] Add regression test for GitHub issue #74132 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: #74132 Thanks Tomas --- .../Regression/GitHub_74132.cs | 46 +++++++++++++++++++ .../Regression/GitHub_74132.csproj | 9 ++++ 2 files changed, 55 insertions(+) create mode 100644 src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_74132.cs create mode 100644 src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_74132.csproj 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 + + + + +