[Mono-bugs] [Bug 418908] New: . cctor type initializer causes buggy IL when using a lambda expression with a parameter

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Aug 20 16:26:54 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=418908


           Summary: .cctor type initializer causes buggy IL when using a
                    lambda expression with a parameter
           Product: Mono: Compilers
           Version: 2.0
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: mono at e-tobi.net
         QAContact: mono-bugs at lists.ximian.com
                CC: mono at e-tobi.net
          Found By: ---


When using a lambda expression with a parameter to initalize a static member,
the generated IL causes an exception.

Please see the code and the exception output below.

This only happens, when the lambda expression has a parameter ("() => true"
works fine). And it only happens when the lambda expression is directly used to
initialize the static member. If I wrap the lambda expression into a static
method and use this method to initialize the static member, then it works
without any problems.

I'm not an expert, but looking at the IL, it seems, that it initializes the "i"
ParameterExpression AFTER passing the ParameterExpression[] array to
System.Linq.Expressions.Expression.Lambda<...>(...)

Here's the code to reproduce the problem;

using System;
using System.Reflection;
using System.Linq.Expressions;

public static class TestCase
{
    // This causes all the trouble:
    public static bool DUMMY = StaticMethodTakingAnExpression((i) => true);

    public static bool StaticMethodTakingAnExpression(
      Expression<Func<object, bool>> expression)
    {
        // I don't execute the expression here!!!
        return false;
    }

    public static void DummyToMakeTheStaticsInitialize()
    {
        // Just a dummy method to make this static class get initialized
    }
}

public class Program
{
    public static void Main()
    {
        TestCase.DummyToMakeTheStaticsInitialize();
    }
}

And this is what happens, when you execute this code:

Unhandled Exception: System.TypeInitializationException: An exception was
thrown by the type initializer for TestCase ---> System.NullReferenceException:
Object reference not set to an instance of an object
  at System.Linq.Expressions.Expression.CheckLambda (System.Type delegateType,
System.Linq.Expressions.Expression body,
System.Collections.ObjectModel.ReadOnlyCollection`1 parameters) [0x0006f] in
/home/tobias/sandbox/x/mcs/class/System.Core/System.Linq.Expressions/Expression.cs:1479 
  at System.Linq.Expressions.Expression.Lambda[Func`2]
(System.Linq.Expressions.Expression body, IEnumerable`1 parameters) [0x00018]
in
/home/tobias/sandbox/x/mcs/class/System.Core/System.Linq.Expressions/Expression.cs:1506 
  at System.Linq.Expressions.Expression.Lambda[Func`2]
(System.Linq.Expressions.Expression body,
System.Linq.Expressions.ParameterExpression[] parameters) [0x00000] in
/home/tobias/sandbox/x/mcs/class/System.Core/System.Linq.Expressions/Expression.cs:1496 
  at TestCase..cctor () [0x00000] in
/tmp/sm/Source/StructureMap.Testing/bin/Debug/test2.cs:1 
  --- End of inner exception stack trace ---
  at Program.Main () [0x00005] in
/tmp/sm/Source/StructureMap.Testing/bin/Debug/test2.cs:26


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list