[Mono-bugs] [Bug 81180][Nor] New - GMCS does not enforce reference type constraint
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Sun Mar 18 23:49:26 EDT 2007
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 tim_boetie at fastmail.fm.
http://bugzilla.ximian.com/show_bug.cgi?id=81180
--- shadow/81180 2007-03-18 22:49:26.000000000 -0500
+++ shadow/81180.tmp.7799 2007-03-18 22:49:26.000000000 -0500
@@ -0,0 +1,52 @@
+Bug#: 81180
+Product: Mono: Compilers
+Version: 1.2
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com
+ReportedBy: tim_boetie at fastmail.fm
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: GMCS does not enforce reference type constraint
+
+GMCS appears to allow one to instantiate generic classes using value types
+for paramaters that have the reference type constraint. The following code
+shouldn't, I think, compile:
+
+namespace Application
+{
+ public class TestClass<T> where T : class
+ {
+ static public T meth()
+ {
+ return null;
+ }
+ }
+
+ public class Test
+ {
+
+ public Test()
+ {
+ }
+
+ static public void Main()
+ {
+ int i = TestClass<int>.meth();
+ System.Console.WriteLine(i);
+ }
+ }
+}
+
+"where T : class" should constrain T to be a reference type, which int is
+not. Furthermore, TestClass.meth returns null, which one shouldn't be able
+to assign to an int.
+
+But, on version 1.2.3.1, it compiles and the resulting executable outputs "0".
More information about the mono-bugs
mailing list