[Mono-bugs] [Bug 367186] New: error CS0029: Cannot implicitly convert type `T' to `T'

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Mar 4 23:12:42 EST 2008


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


           Summary: error CS0029: Cannot implicitly convert type `T' to `T'
           Product: Mono: Compilers
           Version: 1.2.6
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: unsigned_char at yahoo.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development


The following code does not compile:

using System;
public class Y {}
public class X {

        public static void Main(string[] args) {
                TestFn<Y>();
        }
        public static T TestFn<T>() where T : new () {
                T result = default(T);
                RunIt(delegate(int i) {
                        result = Passthrough(new T());
                });
                return result;
        }
        public static void RunIt(Action<int> a) {
                a(1);
        }
        public static T Passthrough<T>(T item) {
                return item;
        }
}


It yields an error of:

debian-003:~# gmcs test.cs
test.cs(11,25): error CS0029: Cannot implicitly convert type `T' to `T'
test.cs(11,25): The generic parameter `T' of `X.<>c__CompilerGenerated0<T>'
cannot be converted to the generic parameter `T' of `X.TestFn<T>()' (in the
previous error)
test.cs(16,17): error CS1593: Delegate `System.Action<int>' does not take `0'
arguments
Compilation failed: 2 error(s), 0 warnings


However, when I remove the RunIt() call and just call the delegate manually, it
compiles:

using System;
public class Y {}
public class X {

        public static void Main(string[] args) {
                TestFn<Y>();
        }
        public static T TestFn<T>() where T : new () {
                T result = default(T);
                Action<int> a = delegate(int i) {
                        result = Passthrough(new T());
                };
                a(1);
                return result;
        }
        public static void RunIt(Action<int> a) {
                a(1);
        }
        public static T Passthrough<T>(T item) {
                return item;
        }
}


The Microsoft compilers will compile both successfully.  Any ideas?

Regards,
Joel Clark
Charlotte, NC
unsigned_char at yahoo.com


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