[Mono-bugs] [Bug 58531][Nor] New - gmcs problem

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 14 May 2004 17:20:06 -0400 (EDT)


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 miguel@ximian.com.

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

--- shadow/58531	2004-05-14 17:20:06.000000000 -0400
+++ shadow/58531.tmp.10994	2004-05-14 17:20:06.000000000 -0400
@@ -0,0 +1,76 @@
+Bug#: 58531
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: martin@ximian.com                            
+ReportedBy: miguel@ximian.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: gmcs problem
+
+From the mailing list 
+-----------------
+
+Actually his code does that properly as far as I can see...
+
+This appears to be a bug in gmcs... Consider the following code which 
+compiles but then chokes when run (of course...). It SHOULD NOT compile 
+as is... And if you change it to USE the ref modifiers like it supposed 
+to, it doesn't work... (Incidentally I tried it with non-generic classes 
+and it works as expected, so it is evidently a problem only with the 
+generics part). (I am using beta1, I am assuming this has not been fixed 
+already; I didn't see anything about it on bugzilla).
+
+Ben Martin
+
+
+// Code to test the ref modifier for generic functions
+
+class RefTest {
+  public void swap <T> (ref T i, ref T j) {
+    T temp;
+    temp = i;
+    i = j;
+    j = temp;
+    return;
+  }
+}
+
+class Stuff <T> {
+
+  public Stuff(T a) {
+    data = a;
+  }
+
+  public void Print() {
+    System.Console.WriteLine("data = {0}", data);
+    return;
+  }
+
+  private T data;
+}
+
+class Driver {
+
+  public static void Main()
+  {
+    RefTest refTest = new RefTest();
+   
+    Stuff<int> x = new Stuff<int>(4);
+    Stuff<int> y = new Stuff<int>(5);
+    refTest.swap<Stuff<int>>(x, y);  // ********* Line 35 **********
+    // Above should NOT work, below SHOULD
+    // refTest.swap<Stuff<int>>(ref x, ref y);
+    x.Print();
+    y.Print();
+  }
+
+}