LambdaExpression created from Lambda different from c#5 compiler

Topics: C# Language Design
Aug 11, 2014 at 8:36 PM
If I create a Lambda like this:
 () => ((Byte)    0)  .ToString()
and use it for a Lambda expression in a Parameter:
 public static MemberInfo MemeberInfo(LambdaExpression func)

the Expression is this:
.Lambda #Lambda1<System.Func`1[System.Object]>() {
    .Call .Constant<System.Byte>(0).ToString()
}
but the ToString used is not the one from byte, no the one from object!
this was different in previous compiler Versions (i think). Because code from here: https://github.com/linq2db/linq2db/blob/master/Source/Linq/Expressions.cs in line 382 and following return the same key, and so dictionary entry does not work any more!
Developer
Aug 12, 2014 at 12:50 AM
Please file an issue.
Aug 12, 2014 at 6:59 AM
Marked as answer by TomasMatousek on 8/12/2014 at 10:41 PM
Aug 13, 2014 at 12:59 PM
i think for backward compatibility the expressions should be the same!
Aug 14, 2014 at 3:19 AM
How to reproduce:
using System;
using System.Linq.Expressions;

namespace VS2013Compatibility
{
    class Program
    {
        static void Main(string[] args)
        {
            Expression<Func<string>> f1 = () => 0.ToString();
            Expression<Func<string>> f2 = () => 0l.ToString();

            var mi1 = ((MethodCallExpression)f1.Body).Method;
            var mi2 = ((MethodCallExpression)f2.Body).Method;
            var mi3 = typeof(int).GetMethod("ToString", new Type[0]);

            Console.WriteLine(mi1 == mi2);
            Console.WriteLine(mi1.DeclaringType);
            Console.WriteLine(mi2.DeclaringType);
            Console.WriteLine(mi3.DeclaringType);
        }
    }
}
VS 2013 Result:
False
System.Int32
System.Int64
System.Int32
VS 2014
True
System.Object
System.Object
System.Int32
Aug 14, 2014 at 10:35 AM
Aug 25, 2014 at 10:47 AM
Any News if this will be fixed?
Developer
Oct 27, 2014 at 10:11 PM
jogibear9988 wrote:
Any News if this will be fixed?
No news. If we address this it will likely be one of the last things we do in the current product cycle.
Oct 27, 2014 at 11:39 PM
What?! Microsoft breaks backward compatibility? O RLY?!
Nov 11, 2014 at 8:55 PM
News to this topic?
Nov 12, 2014 at 12:07 AM
Have a look at https://roslyn.codeplex.com/workitem/246 this was the first case to this topic and it seems to resolve your issue.