[Mono-bugs] [Bug 425669] New: Delegate using an outer generic type parameter doesn' t work right

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Sep 11 18:01:59 EDT 2008


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


           Summary: Delegate using an outer generic type parameter doesn't
                    work right
           Product: Mono: Compilers
           Version: SVN
          Platform: 64bit
        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
          Found By: ---


Simple example:

using System;
using System.Collections;
using System.Collections.Generic;

public class Foo {};
public class Bar {};

public class MainClass
{
    private static readonly List<Action> _actions = new List<Action>();

    public static void Main()
    {
        Test<Foo>();
        Test<Bar>();

        foreach(Action action in _actions)
        {
            action();
        }
    }

    public static void Test<T>()
    {
        _actions.Add( ()=>
        {
            Console.WriteLine(typeof(T));
        });
    }
}

Expected output (proven to work with csc compiled source on Mono and .NET):

Foo
Bar

But output is:

Foo
Foo

If I reverse the order of the Test<T>() calls, I get:

Bar
Bar

So it seems, the delegate remembers the first generic type parameter somehow,
instead of using the second one.

Here's another, smaller test case:

using System;

public class Test
{
        public static int Main ()
        {
                if (Test<string>()() != typeof(string)) return 1;
                if (Test<int>()() != typeof(int)) return 2;
                return 0;
        }

        public static Func<Type> Test<T>()
        {
                return () => typeof(T);
        }
}


-- 
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