Bugzilla – Bug 320149
[GMCS] CS0309: instantiation of generic type with interface constraint using value type
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by horst.reiterer@mind-breeze.com 2006-01-25 16:33:52 MST ---- 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 ---- Additional Comments From martin@ximian.com 2006-02-02 12:10:19 MST ---- Compare this to #77395 - this one (A.cs) is where we must not report an error - #77395 is the opposite case (B.cs) where we do need to report an error. ---- Additional Comments From martin@ximian.com 2006-02-06 12:00:16 MST ---- Fixed in SVN. ---- Additional Comments From martin@ximian.com 2006-02-07 17:40:05 MST ---- . Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>Red Hat Enterprise Linux 4</cf_op_sys_details> Unknown bug field "cf_version_details" encountered while moving bug <cf_version_details>1.1.13</cf_version_details> Unknown operating system other. Setting to default OS "Other".