[Mono-bugs] [Bug 68265][Blo] New - Generics with value type parameters are broken

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 13 Oct 2004 18:11:28 -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 luca.barbieri@gmail.com.

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

--- shadow/68265	2004-10-13 18:11:28.000000000 -0400
+++ shadow/68265.tmp.15614	2004-10-13 18:11:28.000000000 -0400
@@ -0,0 +1,138 @@
+Bug#: 68265
+Product: Mono: Runtime
+Version: unspecified
+OS: 
+OS Details: Fedora Development on Pentium M
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: luca.barbieri@gmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Generics with value type parameters are broken
+
+Description of Problem:
+The attached code doesn't work, which is astounding.
+
+
+Steps to reproduce the problem:
+1. Compile the C# code attached with CVS gmcs and run with CVS mono
+
+Actual Results:
+Unhandled Exception: System.InvalidCastException: Cannot cast from source
+type to destination type.
+in [0x00000] (at /home/lb/pers/src/test.cs:13) MainClass:Main (string[])
+
+Expected Results:
+No exceptions.
+
+
+C# code:
+class MainClass
+{
+        class Gen<T>
+        {
+        }
+
+        class Der : Gen<int>
+        {
+        }
+
+        static int Main(string[] args)
+        {
+                Gen<int> b = (Gen<int>)(object)new Der();
+                return 0;
+        }
+}
+
+
+
+Disassembled IL code:
+.assembly extern mscorlib
+{
+  .ver 2:0:3600:0
+  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
+}
+.assembly 'test'
+{
+  .hash algorithm 0x00008004
+  .ver  0:0:0:0
+}
+.module test.exe // GUID = {C792D86F-B92C-41AF-8420-E7F2C08BE1AD}
+
+
+  .class private auto ansi beforefieldinit MainClass
+        extends [mscorlib]System.Object
+  {
+
+    // method line 1
+    .method public hidebysig  specialname  rtspecialname
+           instance default void .ctor ()  cil managed
+    {
+        // Method begins at RVA 0x20ec
+        // Code size 7 (0x7)
+        .maxstack 8
+        IL_0000:  ldarg.0
+        IL_0001:  call instance void class [mscorlib]System.Object::.ctor()
+        IL_0006:  ret
+    } // end of method MainClass::instance default void .ctor ()
+
+    // method line 2
+    .method private static  hidebysig
+           default int32 Main (string[] args)  cil managed
+    {
+        // Method begins at RVA 0x20f4
+        .entrypoint
+        // Code size 13 (0xd)
+        .maxstack 2
+        .locals init (
+                class 'MainClass/Gen`1'<int32>  V_0)
+        IL_0000:  newobj instance void class 'MainClass/Der'::.ctor()
+        IL_0005:  castclass class 'MainClass/Gen`1'<int32>
+        IL_000a:  stloc.0
+        IL_000b:  ldc.i4.0
+        IL_000c:  ret
+    } // end of method MainClass::default int32 Main (string[] args)
+
+  .class nested private auto ansi beforefieldinit 'Gen`1'<T>
+        extends [mscorlib]System.Object
+  {
+
+    // method line 3
+    .method public hidebysig  specialname  rtspecialname
+           instance default void .ctor ()  cil managed
+    {
+        // Method begins at RVA 0x2110
+        // Code size 7 (0x7)
+        .maxstack 8
+        IL_0000:  ldarg.0
+        IL_0001:  call instance void class [mscorlib]System.Object::.ctor()
+        IL_0006:  ret
+    } // end of method Gen`1::instance default void .ctor ()
+
+  } // end of class Gen`1
+
+  .class nested private auto ansi beforefieldinit Der
+        extends class 'MainClass/Gen`1'<int32>
+  {
+
+    // method line 4
+    .method public hidebysig  specialname  rtspecialname
+           instance default void .ctor ()  cil managed
+    {
+        // Method begins at RVA 0x2118
+        // Code size 7 (0x7)
+        .maxstack 8
+        IL_0000:  ldarg.0
+        IL_0001:  call instance void class 'MainClass/Gen`1'<int32>::.ctor()
+        IL_0006:  ret
+    } // end of method Der::instance default void .ctor ()
+
+  } // end of class Der
+
+  } // end of class MainClass