[Mono-bugs] [Bug 77522][Maj] New - [GMCS] Runtime doesn't check
constraints
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Fri Feb 10 04:24:55 EST 2006
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by martin at ximian.com.
http://bugzilla.ximian.com/show_bug.cgi?id=77522
--- shadow/77522 2006-02-10 04:24:55.000000000 -0500
+++ shadow/77522.tmp.12865 2006-02-10 04:24:55.000000000 -0500
@@ -0,0 +1,68 @@
+Bug#: 77522
+Product: Mono: Compilers
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Major
+Component: C#
+AssignedTo: martin at ximian.com
+ReportedBy: martin at ximian.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: [GMCS] Runtime doesn't check constraints
+
+Our runtime doesn't check the constraints when instantiating a generic type.
+
+For instance in the following example, Type.MakeGenericType() must throw an
+ArgumentException.
+
+=====
+using System;
+
+public class Foo<T>
+ where T : struct
+{ }
+
+class X
+{
+ static void Main ()
+ {
+ Type t = typeof (Foo<>);
+ t.MakeGenericType (typeof (X));
+ }
+}
+=====
+
+On Windows, this is throwing at runtime:
+
+=====
+martin at mordor ~
+$ csc N.cs
+Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.7
+for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
+Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
+
+
+martin at mordor ~
+$ ./N.exe
+
+Unhandled Exception: System.ArgumentException: GenericArguments[0], 'X', on
+'Foo`1[T]' violates the constraint of type 'T'. --->
+System.TypeLoadException: GenericArguments[0], 'X', on 'Foo`1[T]' violates
+the constraint of type parameter 'T'.
+ at System.RuntimeTypeHandle._Instantiate(RuntimeTypeHandle[] inst)
+ at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle[] inst)
+ at System.RuntimeType.MakeGenericType(Type[] instantiation)
+ --- End of inner exception stack trace ---
+ at System.RuntimeType.ValidateGenericArguments(MemberInfo definition,
+Type[] genericArguments, Exception e)
+ at System.RuntimeType.MakeGenericType(Type[] instantiation)
+ at X.Main()
+
+martin at mordor ~
+===============
More information about the mono-bugs
mailing list