Bug 439125 - CS0309 with generic methods where constraints have generic parameters
Summary: CS0309 with generic methods where constraints have generic parameters
Status: RESOLVED DUPLICATE of bug 537402
Alias: None
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 2.4.x
Hardware: x86-64 Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL: http://www.postsharp.org/
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-27 08:25 UTC by Gael Fraiteur
Modified: 2009-09-08 16:55 UTC (History)
1 user (show)

See Also:
Found By: Customer
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gael Fraiteur 2008-10-27 08:25:53 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
Comment 1 Marek Safar 2009-01-28 12:41:30 UTC
Could you please attach a test which reproduces the issue?
Comment 2 Eugene Shalygin 2009-03-11 18:02:33 UTC
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
Comment 3 Eugene Shalygin 2009-03-13 11:59:20 UTC
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]
Comment 4 Eugene Shalygin 2009-03-31 14:51:16 UTC
Still exists in mono-2.4
Comment 5 Marek Safar 2009-09-08 16:55:45 UTC
Fixed in trunk.

*** This bug has been marked as a duplicate of bug 537402 ***