[Mono-bugs] [Bug 76097][Maj] New - Type checker ignores generic type parameter constraint

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Sep 14 03:06:50 EDT 2005


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 sestoft at dina.kvl.dk.

http://bugzilla.ximian.com/show_bug.cgi?id=76097

--- shadow/76097	2005-09-14 03:06:50.000000000 -0400
+++ shadow/76097.tmp.22423	2005-09-14 03:06:50.000000000 -0400
@@ -0,0 +1,69 @@
+Bug#: 76097
+Product: Mono: Compilers
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: sestoft at dina.kvl.dk               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Type checker ignores generic type parameter constraint
+
+Description of Problem:
+
+The gmcs 1.1.9 type checker does not take type parameter constraint Aa : Af
+into account when checking method body.
+
+Steps to reproduce the problem:
+1. Compile the program inserted below
+2. Observe unexpected compiler error message
+
+Actual Results:
+
+Bug15.cs(24,20): error CS1594: Delegate `Fun<Af,Rf>' has some invalid arguments
+Bug15.cs(24,20): error CS1503: Argument 1: Cannot convert from `Aa' to `in Af'
+Compilation failed: 2 error(s), 0 warnings
+
+Expected Results:
+
+It should compile without problems, and does in MS beta 2.
+
+// -------------------
+
+using System;
+using System.Collections.Generic;
+
+class MyTest {
+  public static void Main(String[] args) {
+    foreach (Object d in Map<int,int,String,Object>
+	                    (delegate (int x) { return x.ToString(); }, 
+			     FromTo(10,20)))
+      Console.WriteLine(d);
+  }
+
+  // Map with argument/result co/contravariance:
+  // Aa=argument, Rr=result, Af=f's argument, Rf=f's result
+
+  public static IEnumerable<Rr> Map<Aa,Af,Rf,Rr>(Fun<Af,Rf> f, 
+                                                 IEnumerable<Aa> xs) 
+    where Aa : Af 
+    where Rf : Rr 
+  { 
+    foreach (Aa x in xs)
+      yield return f(x);    // gmcs 1.1.9 bug: cannot convert Aa to Af
+  }
+
+  // FromTo : int * int -> int stream
+
+  public static IEnumerable<int> FromTo(int from, int to) { 
+    for (int i=from; i<=to; i++)
+      yield return i;
+  }
+}


More information about the mono-bugs mailing list