Bugzilla – Bug 324072
[GMCS] Generic constraints not compiled correctly
Last modified: 2008-09-19 15:17:21 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)
*** This bug has been marked as a duplicate of bug 416110 ***