Bugzilla – Bug 439125
CS0309 with generic methods where constraints have generic parameters
Last modified: 2009-09-08 16:55:45 UTC
Description of Problem: The C# compiler does not compile a program with a generic method where constraints contain generic parameters. Steps to reproduce the problem: Compile Program.cs Actual Results: error CS0309: The type `System.Collections.Generic.List<int>' must be convertible to `System.Collections.Generic.IList<System.Collections.Generic.List<int>>' in order to use it as parameter `T2' in the generic type or method `MonoBug.GenericClass<T1>.GenericMethod<T2,T3>(T2, T3)' Expected Results: Should compile. How often does this happen? Always. Additional Information: Using 2.0.1
Could you please attach a test which reproduces the issue?
I guess that I'm able to provide required information. Here is sample program: using System; namespace test { interface I<T> { T Get(); } class G<A,C> where C:struct, I<A> { public void M<CA>(G<A, CA> g) where CA:struct, I<A> { } } struct Iint1:I<int> { public int Get() { return 0; } } struct Iint2:I<int> { public int Get() { return 0; } } class MainClass { public static void Main (string[] args) { G<int, Iint1> gint1 = new G<int, Iint1>(); G<int, Iint2> gint2 = new G<int, Iint2>(); gint1.M<Iint2>(gint2); } } } compiler output: /home/eugene/Projects/test/test/Main.cs(46,31): error CS0309: The type `test.Iint2' must be convertible to `test.I<test.Iint2>' in order to use it as parameter `CA' in the generic type or method `test.G<A,C>.M<CA>(test.G<A,CA>)' /home/eugene/Projects/test/test/Main.cs(18,29): (Location of the symbol related to previous error) /home/eugene/Projects/test/test/Main.cs(32,16): (Location of the symbol related to previous error) $ mono --version Mono JIT compiler version 2.2 (tarball Tue Jan 27 22:46:36 EET 2009) $ uname -srmi Linux 2.6.28-tuxonice-r4 x86_64 GenuineIntel
current svn version failed to compile this code and results in ICE: $ mono gmcs.exe /home/eugene/Projects/test/test/Main.cs Unhandled Exception: Mono.CSharp.InternalErrorException: /home/eugene/Projects/test/test/Main.cs(24,16): test.Iint1 ---> Mono.CSharp.InternalErrorException: Parameters are not registered for method `test.I<int>.Get' at Mono.CSharp.TypeManager.GetParameterData (System.Reflection.MethodBase mb) [0x00000] at Mono.CSharp.PendingImplementation..ctor (Mono.CSharp.TypeContainer container, .MissingInterfacesInfo[] missing_ifaces, System.Collections.ArrayList abstract_methods, Int32 total) [0x00000] at Mono.CSharp.PendingImplementation.GetPendingImplementations (Mono.CSharp.TypeContainer container) [0x00000] at Mono.CSharp.TypeContainer.DoDefineMembers () [0x00000] at Mono.CSharp.TypeContainer.Define () [0x00000] at Mono.CSharp.ClassOrStruct.Define () [0x00000] at Mono.CSharp.RootContext.PopulateTypes () [0x00000] --- End of inner exception stack trace --- at Mono.CSharp.RootContext.PopulateTypes () [0x00000] at Mono.CSharp.Driver.Compile () [0x00000] at Mono.CSharp.Driver.Main (System.String[] args) [0x00000]
Still exists in mono-2.4
Fixed in trunk. *** This bug has been marked as a duplicate of bug 537402 ***