[Mono-bugs] [Bug 79525][Maj] New - cast to generic valuetypes fails at runtime

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Sep 29 08:39:09 EDT 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 dignor_sign at yahoo.es.

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

--- shadow/79525	2006-09-29 08:39:09.000000000 -0400
+++ shadow/79525.tmp.7674	2006-09-29 08:39:09.000000000 -0400
@@ -0,0 +1,84 @@
+Bug#: 79525
+Product: Mono: Compilers
+Version: 1.1
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: dignor_sign at yahoo.es               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: cast to generic valuetypes fails at runtime
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+Mono refuses to run cast code generated from gmcs.
+
+Steps to reproduce the problem:
+1. Compile this program with : "gmcs program.cs"
+
+interface Interface1<T>{
+}
+
+class Generic1<T>{
+
+   class Nested:Interface1<T>{
+       public void salute()
+       {
+             System.Console.WriteLine("Hello world");
+       }
+   }
+
+   public Interface1<T> getAnInstance()
+   {
+       return new Nested();
+   }
+
+   public void test( Interface1<T> gi)
+   {
+       Nested n = (Nested) gi;
+       n.salute();
+   }
+
+}
+
+class App {
+   public static void Main()
+   {
+       Generic1<int> g1 = new Generic1<int>();
+       Interface1<int> gi = g1.getAnInstance();
+       g1.test(gi);
+   }
+}
+
+2. Execute with mono program.exe
+
+
+Actual Results:
+
+System.InvalidProgram...
+Illegal IL code ....stloc.0
+
+Expected Results:
+
+"Hello world"
+
+How often does this happen? 
+
+Always
+
+Additional Information:
+
+The compiler generates a castclass instead of an unboxing cast in the test
+method, and in fact, it's not a compiler problem, but a bug deep in the
+mono internals that makes Type.IsClass to return true for a generic value
+type during the type construction. Type.IsClass works right, however, if
+the test is done inside the target program.


More information about the mono-bugs mailing list