Bug 324072 (MONO81392) - [GMCS] Generic constraints not compiled correctly
Summary: [GMCS] Generic constraints not compiled correctly
Status: RESOLVED DUPLICATE of bug 416110
Alias: MONO81392
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Other All
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-18 10:35 UTC by Alp Toker
Modified: 2008-09-19 15:17 UTC (History)
0 users

See Also:
Found By: ---
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 Thomas Wiest 2007-09-15 20:35:49 UTC


---- Reported by alp@atoker.com 2007-04-18 03:35:46 MST ----

With this test case:

using System;
using System.Reflection;

class foo
{
		public static int GenericCompare<T> (Nullable<T> left, Nullable<T> right)
where T: struct
		{
			return 0;
		}

		public static void Main ()
		{
			MethodInfo mi = typeof (foo).GetMethod ("GenericCompare");
			Console.WriteLine (mi.Name);

			//MethodInfo mi = method as MethodInfo;
			Type [] genArgs = mi == null ? Type.EmptyTypes :
				mi.GetGenericArguments ();
			if (genArgs.Length > 0) {
				string [] genArgNames = new string [genArgs.Length];
				for (int i = 0; i < genArgs.Length; i++) {
					genArgNames [i] = genArgs [i].Name;
					string genArgCsts = String.Empty;
					Console.WriteLine ("genArgs [i]: " + genArgs [i]);
					Type [] gcs = genArgs [i].GetGenericParameterConstraints ();
					Console.WriteLine ("gcs.Length: " + gcs.Length);
					if (gcs.Length > 0) {
						string [] gcNames = new string [gcs.Length];
						for (int g = 0; g < gcs.Length; g++)
							gcNames [g] = gcs [g].FullName;
						genArgCsts = String.Concat (
							"(",
							string.Join (", ", gcNames),
							") ",
							genArgNames [i]);
					}
					else
						genArgCsts = genArgNames [i];
					if ((genArgs [i].GenericParameterAttributes &
GenericParameterAttributes.ReferenceTypeConstraint) != 0)
						genArgCsts = "class " + genArgCsts;
					else if ((genArgs [i].GenericParameterAttributes &
GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
						genArgCsts = "struct " + genArgCsts;
					genArgNames [i] = genArgCsts;
				}
				string ret = String.Format ("{0}<{2}>({1})",
					"name",
					"parms",
					string.Join (",", genArgNames));

				Console.WriteLine (ret);
			}
		}
}


When compiled with gmcs, the output on both Mono and MS .NET is:

GenericCompare
genArgs [i]: T
gcs.Length: 0
name<struct T>(parms)


When compiled with csc, the output on MS .NET is:

GenericCompare
genArgs [i]: T
gcs.Length: 1
name<struct (System.ValueType) T>(parms)

Comment 2 Marek Safar 2008-09-19 15:17:21 UTC

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