[Mono-bugs] [Bug 77358][Nor] New - CS0309: instantiation of generic
type with interface constraint using value type
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Wed Jan 25 16:33:52 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 horst.reiterer at mind-breeze.com.
http://bugzilla.ximian.com/show_bug.cgi?id=77358
--- shadow/77358 2006-01-25 16:33:52.000000000 -0500
+++ shadow/77358.tmp.4956 2006-01-25 16:33:52.000000000 -0500
@@ -0,0 +1,82 @@
+Bug#: 77358
+Product: Mono: Compilers
+Version: 1.1
+OS: other
+OS Details: Red Hat Enterprise Linux 4
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com
+ReportedBy: horst.reiterer at mind-breeze.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: CS0309: instantiation of generic type with interface constraint using value type
+
+The following testcase fails to compile with Mono 1.1.13's gmcs. The
+testcase defines a generic type with an interface constraint. Instantiating
+the generic type with a reference type implementing the required interface
+succeeds, doing the same with a value type fails to compile - it succeeds
+with Microsoft's csc.
+
+using System;
+
+public class Container<T> where T : IComparable<T>
+{
+}
+
+public class ReferenceType : IComparable<ReferenceType>
+{
+ public int value;
+
+ public int CompareTo(ReferenceType obj)
+ {
+ return 0;
+ }
+};
+
+public struct ValueType : IComparable<ValueType>
+{
+ public int value;
+
+ public int CompareTo(ValueType obj)
+ {
+ return 0;
+ }
+};
+
+public class Test
+{
+ public static void Main(string[] args)
+ {
+ // Compilation succeeds, constraint satisfied
+ new Container<ReferenceType>();
+
+ // Compilation fails, constraint not satisfied according to mcs,
+ // the unmodified testcase compiles successfully with csc
+ new Container<ValueType>();
+ }
+};
+
+Steps to reproduce the problem:
+1. gmcs testcase.cs
+
+Actual Results:
+
+testcase.cs(36,9): error CS0309: The type `ValueType' must be convertible
+to `System.IComparable<T>' in order to use it as parameter `T' in the
+generic type or method `Container<T>'
+testcase.cs(3,14):: `Container<T>', name of symbol related to previous error
+testcase.cs(17,15):: `ValueType', name of symbol related to previous error
+Compilation failed: 1 error(s), 0 warnings
+
+Expected Results:
+
+Successful compilation
+
+How often does this happen?
+
+100 out of 100 times
More information about the mono-bugs
mailing list