Bug 517028 - Strange LINQ Expression behaviour
Summary: Strange LINQ Expression behaviour
Status: NEW
Alias: None
Product: Mono: Class Libraries
Classification: Mono
Component: Sys.Core (show other bugs)
Version: SVN
Hardware: x86-64 Linux
: P5 - None : Normal
Target Milestone: 2.4.x
Assignee: Michael Miller
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-26 20:26 UTC by Federico Di Gregorio
Modified: 2011-09-17 18:01 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Federico Di Gregorio 2009-06-26 20:26:45 UTC
The simple code that follows shows two different problems detailed below.

using System;
using System.Linq.Expressions;

class Test
{
    public static void Main()
    {
        int? i = 0;
        Expression<Func<String>> e3 = Expression.Lambda<Func<String>>(
            Expression.Convert(Expression.Constant(i), typeof(String),
                               typeof(Convert).GetMethod("ToString", new Type[1] { typeof(int?) })));
        Console.WriteLine("SHOULD NOT WHIS BE NULL? " + typeof(Convert).GetMethod("ToString", new Type[1] { typeof(int?) }));
        Console.WriteLine(e3.Compile()());
    }
}

Problems:

While Convert does not have a ToString(Int32?) method, GetMethod returns a method with ToString(Object) as signature instead of null.

The program fails during Compile() with a "System.InvalidProgramException: Invalid IL code" exception.
Comment 1 Miguel de Icaza 2009-06-26 20:29:38 UTC
The problem is that our LINQ implementation should throw an exception because there is a parameter mismatch.

.NET reports:

InvalidOperationException: The operatnds for operator 'Convert' do not match the parameter of method 'ToString'.

We instead silently compile incorrect code