Type.IsAssignableFrom works incorrect in special cases
iskiselev opened this issue · comments
Type.IsAssignableFrom
works incorrect for nullable and arrays:
using JSIL.Meta;
using JSIL.Proxy;
using System;
public static class Program
{
public static void Main(string[] args)
{
Console.WriteLine(typeof(Struct?).IsAssignableFrom(typeof(Struct)) ? "true" : "false");
Console.WriteLine(typeof(Struct).IsAssignableFrom(typeof(Struct?)) ? "true" : "false");
Console.WriteLine(typeof(object[]).IsAssignableFrom(typeof(Struct[])) ? "true" : "false");
Console.WriteLine(typeof(Struct[]).IsAssignableFrom(typeof(object[])) ? "true" : "false");
Console.WriteLine(typeof(object[]).IsAssignableFrom(typeof(Class[])) ? "true" : "false");
Console.WriteLine(typeof(Class[]).IsAssignableFrom(typeof(object[])) ? "true" : "false");
}
}
public class Class { }
public struct Struct { }
public class Base { }
public class Derived1 : Base { }
public class Derived2 : Base { }
The easiest way to fix it will be add several more special cases in JSIL.MakeType
assignment of typeObject._IsAssignableFrom
, but it will duplicate logic of CheckType
method for arrays/nullables. Probably we need some generic solution here.
EDITED: I believe we should move _IsAssignableFrom into JSIL.MakeCastMethods, or just remove_IsAssignableFrom at all and fully implement IsAssignableFrom
inside System.Type.js