diff options
4 files changed, 49 insertions, 1 deletions
diff --git a/src/coreclr/vm/methodtable.cpp b/src/coreclr/vm/methodtable.cpp index 98c3d6fd0c1..4362dfae316 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 00000000000..b5ddc253063 --- /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<in T> +{ + static virtual string DoStatic() => typeof(T).ToString(); +} + +interface IFoo2<in T> +{ + static abstract string DoStatic(); +} + +class Fooer<T> : IFoo2<T> +{ + public static string DoStatic() => typeof(T).ToString(); +} + +class Program : IFoo<object> +{ + static string CallStatic<T, U>() where T : IFoo<U> => T.DoStatic(); + static string CallStatic2<T, U>() where T : IFoo2<U> => T.DoStatic(); + + static int Main() + { + string staticResult1 = CallStatic<Program, string>(); + Console.WriteLine("SVM call result #1: {0} (System.Object expected - using default interface implementation)", staticResult1); + string staticResult2 = CallStatic2<Fooer<object>, 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 00000000000..88b66b37801 --- /dev/null +++ b/src/tests/Loader/classloader/StaticVirtualMethods/RegressionTests/GitHub_71319.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>Exe</OutputType> + </PropertyGroup> + <PropertyGroup> + <DebugType>Full</DebugType> + </PropertyGroup> + <ItemGroup> + <Compile Include="$(MSBuildThisFileName).cs" /> + </ItemGroup> +</Project> diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 17208a61c35..e96abfed09b 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1519,6 +1519,9 @@ <ExcludeList Include="$(XunitTestBinBase)/Loader/classloader/MethodImpl/CovariantReturns/Structs/IncompatibleOverride/**"> <Issue>Crashes during LLVM AOT compilation.</Issue> </ExcludeList> + <ExcludeList Include="$(XunitTestBinBase)/Loader/classloader/StaticVirtualMethods/RegressionTests/GitHub_71319/**"> + <Issue>https://github.com/dotnet/runtime/issues/71910</Issue> + </ExcludeList> <ExcludeList Include="$(XunitTestBinBase)/JIT/HardwareIntrinsics/General/HwiOp/CompareVectorWithZero/**"> <Issue>https://github.com/dotnet/runtime/pull/65632#issuecomment-1046294324</Issue> |