dynamicexpresso / DynamicExpresso

C# expressions interpreter
http://dynamic-expresso.azurewebsites.net/
MIT License
2.01k stars 379 forks source link

Generic IEnumerable missintepreted #217

Closed waclaw66 closed 2 years ago

waclaw66 commented 2 years ago

The last test fails with Expression of type 'System.Collections.Generic.IEnumerable`1[T]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[System.Object]' of method 'Boolean Any[Object](System.Collections.Generic.IEnumerable`1[System.Object])'

public class Utils
{
    public static bool Any<T>(IEnumerable<T> collection)
    {
        return false;
    }

    public static bool Any(IEnumerable collection)
    {
        return false;
    }
}

var target = new Interpreter();
target.Reference(typeof(Utils));
target.Reference(typeof(IEnumerable<>));

Assert.DoesNotThrow(() => Utils.Any((IEnumerable<object>)null));
Assert.DoesNotThrow(() => Utils.Any(null));
Assert.DoesNotThrow(() => target.Eval("Utils.Any(list)", new Parameter("list", typeof(IEnumerable<object>), null)));
Assert.DoesNotThrow(() => target.Eval("Utils.Any(null)"));
metoule commented 2 years ago

After PR #210, there's a different exception:

System.ArgumentException : Type System.Collections.Generic.IEnumerable`1[T] contains generic parameters (Parameter 'type')   TypeUtils.ValidateType(Type type, String paramName, Int32 index)   TypeUtils.ValidateType(Type type, String paramName, Boolean allowByRef, Boolean allowPointer)   Expression.Constant(Object value, Type type)   Parser.PromoteExpression(Expression expr, Type type, Boolean exact) line 2182