Bugzilla – Bug 324741
gmcs does not emit generic parameter constraints on structs
Last modified: 2008-09-19 15:16:16 UTC
---- Reported by atsushi@ximian.com 2007-07-11 07:29:57 MST ---- Looks like gmcs or SRE does not emit generic parameter constraints. Here is an example (which also contains test for https://bugzilla.novell.com/show_bug.cgi?id=MONO82064), ran on cygwin (note that #82064 is for runtime). $ cat get-arg.cs using System; using System.Collections.Generic; using System.Reflection; public struct Foo<T> where T : struct { } public class Test { public static void Main () { DoTest (typeof (Foo<int>)); DoTest (typeof (int?)); } static void DoTest (Type type) { Type t = type.GetGenericTypeDefinition (); Type n = t.GetGenericArguments () [0]; Console.WriteLine ("{0} {1} {2}", t, n, n.GetGenericParameterConstraints ().Length); } } atsushi@PC ~/tests/generic $ csc get-arg.cs Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1318 for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727 Copyright (C) Microsoft Corporation 2001-2005. All rights reserved. atsushi@PC ~/tests/generic $ ./get-arg.exe Foo`1[T] T 1 System.Nullable`1[T] T 1 atsushi@PC ~/tests/generic $ mono ./get-arg.exe Foo`1[T] T 1 System.Nullable`1[T] T 0 atsushi@PC ~/tests/generic $ gmcs get-arg.cs atsushi@PC ~/tests/generic $ ./get-arg.exe Foo`1[T] T 0 System.Nullable`1[T] T 1 atsushi@PC ~/tests/generic $ mono get-arg.exe Foo`1[T] T 0 System.Nullable`1[T] T 0 ---- Additional Comments From atsushi@ximian.com 2007-07-19 22:06:20 MST ---- It is a difference between ClassConstraint and EffectiveBaseClass in Mono.CSharp.Constraints. Replacing former with latter in DefineType() solves this individual issue, but causes some regressions. Unknown operating system unknown. Setting to default OS "Other".
*** This bug has been marked as a duplicate of bug 416110 ***