diff --git a/src/coreclr/vm/methodtable.cpp b/src/coreclr/vm/methodtable.cpp index 98c3d6fd0c193..4362dfae316b1 100644 --- a/src/coreclr/vm/methodtable.cpp +++ b/src/coreclr/vm/methodtable.cpp @@ -8042,7 +8042,7 @@ MethodTable::ResolveVirtualStaticMethod( if (allowVariantMatches) { - equivalentOrVariantCompatible = pItfInMap->CanCastTo(pInterfaceType, NULL); + equivalentOrVariantCompatible = pItfInMap->CanCastToInterface(pInterfaceType, NULL); } else { diff --git a/src/tests/Loader/classloader/StaticVirtualMethods/RegressionTests/GitHub_71319.cs b/src/tests/Loader/classloader/StaticVirtualMethods/RegressionTests/GitHub_71319.cs new file mode 100644 index 0000000000000..b5ddc2530637c --- /dev/null +++ b/src/tests/Loader/classloader/StaticVirtualMethods/RegressionTests/GitHub_71319.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +interface IFoo +{ + static virtual string DoStatic() => typeof(T).ToString(); +} + +interface IFoo2 +{ + static abstract string DoStatic(); +} + +class Fooer : IFoo2 +{ + public static string DoStatic() => typeof(T).ToString(); +} + +class Program : IFoo +{ + static string CallStatic() where T : IFoo => T.DoStatic(); + static string CallStatic2() where T : IFoo2 => T.DoStatic(); + + static int Main() + { + string staticResult1 = CallStatic(); + Console.WriteLine("SVM call result #1: {0} (System.Object expected - using default interface implementation)", staticResult1); + string staticResult2 = CallStatic2, string>(); + Console.WriteLine("SVM call result #2: {0} (System.Object expected - using implementation in a helper class)", staticResult2); + return (staticResult1 == "System.Object" && staticResult2 == "System.Object" ? 100 : 101); + } +} \ No newline at end of file diff --git a/src/tests/Loader/classloader/StaticVirtualMethods/RegressionTests/GitHub_71319.csproj b/src/tests/Loader/classloader/StaticVirtualMethods/RegressionTests/GitHub_71319.csproj new file mode 100644 index 0000000000000..88b66b3780184 --- /dev/null +++ b/src/tests/Loader/classloader/StaticVirtualMethods/RegressionTests/GitHub_71319.csproj @@ -0,0 +1,11 @@ + + + Exe + + + Full + + + + + diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 17208a61c3525..e96abfed09bdc 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1519,6 +1519,9 @@ Crashes during LLVM AOT compilation. + + https://github.com/dotnet/runtime/issues/71910 + https://github.com/dotnet/runtime/pull/65632#issuecomment-1046294324