sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

Variance generic method is not resolved when called through MethodSignature #990

Open iskiselev opened 8 years ago

iskiselev commented 8 years ago

Variance generic method is not resolved when called through MethodSignature. Test case:

using System;

public static class Program
{
    public static void Main(string[] args)
    {
        var @base = new Base();
        var derived = new Derived();

        Interface<Base> a = new Class();
        a.RunMe(@base);

        Interface<Derived> b = a;
        b.RunMe(derived);
    }
}

public interface Interface<in T>
{
    void RunMe(T arg);
    void RunMe(string arg);
}

public class Class : Interface<Base>
{
    public void RunMe(Base arg)
    {
        Console.WriteLine(arg.GetType().Name);
    }
    public void RunMe(string arg)
    {
        Console.WriteLine("RunMe(string arg)");
    }
}

public class Base { }
public class Derived : Base { }

So, it happens when we try to do variance call to overload interface method with varinace.

iskiselev commented 8 years ago

Probably we really need move all variance helper functions from InterfaceMethod to MethodSignature, after it we could simply use CallInterface/CallVariance internally for MethodSignature that use InterfaceMethod as name argument.

kg commented 8 years ago

Moving variance to signatures sounds sensible.