This project is read-only.

LambdaExpression created from Lambda different from c#5 compiler

Topics: C# Language Design
Aug 11, 2014 at 9: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!
Aug 12, 2014 at 1:50 AM
Please file an issue.
Aug 12, 2014 at 7:59 AM
Marked as answer by TomasMatousek on 8/12/2014 at 10:41 PM
Aug 13, 2014 at 1:59 PM
i think for backward compatibility the expressions should be the same!
Aug 14, 2014 at 4: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 11:35 AM
Aug 25, 2014 at 11:47 AM
Any News if this will be fixed?
Oct 27, 2014 at 11: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 28, 2014 at 12:39 AM
What?! Microsoft breaks backward compatibility? O RLY?!
Nov 11, 2014 at 9:55 PM
News to this topic?
Nov 12, 2014 at 1: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.