1

Closed

TypeIs bug with void

description

Expression.TypeIs should throw an ArgumentException if being passed typeof (void).
Closed Apr 30, 2010 at 8:22 PM by dinov

comments

jmesserly wrote Apr 20, 2010 at 10:52 PM

This behavior existed in 3.5. It's arguably a bug, but it's hard to justify changing it at this point. 3.5 repro:
class Program {
    public static void Main(string[] args) {
        if (args == null) return;
        var e = Expression.Call(typeof(Program).GetMethod("Main"), Expression.Constant(null, typeof(string[])));
        var result = Expression.Lambda<Func<bool>>(Expression.TypeIs(e, typeof(void))).Compile()();
        Console.WriteLine(result);
    }
}

jbevain wrote Apr 22, 2010 at 10:10 AM

Fine with me, although it doesn't make much sense. Your sample test a void method against void, and prints False. Which is correct, as nothing has for type void, but you can always wonder if a void expression in TypeIs(void) should return True.

I personally would throw to avoid any issue.

wrote Apr 30, 2010 at 8:22 PM

wrote Feb 21, 2013 at 10:41 PM

wrote May 16, 2013 at 10:29 AM