-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Description
For the following program:
using System;
interface IFoo<in T>
{
static virtual void DoStatic() => Console.WriteLine(typeof(IFoo<T>));
}
class Program : IFoo<object>
{
static void CallStatic<T, U>() where T : IFoo<U> => T.DoStatic();
static void Main()
{
CallStatic<Program, string>();
}
}My expectation is that we're doing a variant dispatch to IFoo<object> implemented on Program. But unexpectedly, the program prints IFoo`1[System.String]. Somehow we dispatched to an interface Program doesn't implement.
If I modify the program to not use default interface methods, the program prints object as expected.
using System;
interface IFoo<in T>
{
static abstract void DoStatic();
}
class Fooer<T> : IFoo<T>
{
public static void DoStatic() => Console.WriteLine(typeof(T));
}
class Program
{
static void CallStatic<T, U>() where T : IFoo<U> => T.DoStatic();
static void Main()
{
CallStatic<Fooer<object>, string>();
}
}Reactions are currently unavailable