|
Bugzilla – Full Text Bug Listing |
| Summary: | Strange LINQ Expression behaviour | ||
|---|---|---|---|
| Product: | [Mono] Mono: Class Libraries | Reporter: | Federico Di Gregorio <fog> |
| Component: | Sys.Core | Assignee: | Michael Miller <michael.miller> |
| Status: | NEW --- | QA Contact: | Mono Bugs <mono-bugs> |
| Severity: | Normal | ||
| Priority: | P5 - None | ||
| Version: | SVN | ||
| Target Milestone: | 2.4.x | ||
| Hardware: | x86-64 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Found By: | --- | Services Priority: | |
| Business Priority: | Blocker: | --- | |
| Marketing QA Status: | --- | IT Deployment: | --- |
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 |
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.