[svn] r7041: nemerle/trunk/ncc: generation/ILEmitter.n testsuite/positive/boxing.n

malekith svnadmin at nemerle.org
Mon Dec 4 12:47:11 CET 2006


Log:
Emit 'box' also when casting from generic parameter to another. Resolves #801.

Author: malekith
Date: Mon Dec  4 12:47:10 2006
New Revision: 7041

Modified:
   nemerle/trunk/ncc/generation/ILEmitter.n
   nemerle/trunk/ncc/testsuite/positive/boxing.n

Modified: nemerle/trunk/ncc/generation/ILEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/ILEmitter.n	(original)
+++ nemerle/trunk/ncc/generation/ILEmitter.n	Mon Dec  4 12:47:10 2006
@@ -779,7 +779,7 @@
 
         | TypeConversion (expr, cast_to_type, _) when cast_to_type.SystemType.IsGenericParameter =>
           emit (expr);
-          when (expr.Type.Fix().IsValueType)
+          when (expr.MType.IsValueType || expr.MType is MType.TyVarRef)
             _ilg.Emit (OpCodes.Box, expr.SystemType);
           _ilg.Emit (OpCodes.Unbox_Any, cast_to_type.SystemType);
           

Modified: nemerle/trunk/ncc/testsuite/positive/boxing.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/boxing.n	(original)
+++ nemerle/trunk/ncc/testsuite/positive/boxing.n	Mon Dec  4 12:47:10 2006
@@ -10,6 +10,37 @@
   }
 }
 
+namespace Bug801 {
+public class GenericCast[F, T]
+{
+        private from : F;
+
+        public this(from : F)
+        {
+                this.from = from
+        }
+
+        public Run() : T
+        {
+                from :> T
+        }
+}
+
+public class Runner
+{
+        public static Go() : void
+        {
+                def c = GenericCast(100);
+                try {
+                  System.Console.WriteLine (GenericCast (42).Run () : int);
+                  _ = c.Run() : byte
+                } catch { 
+                  | _ is System.InvalidCastException =>
+                    System.Console.WriteLine ("OK, got InvalidCast");
+                }
+        }
+}
+}
 
 module M {
 
@@ -103,6 +134,9 @@
     f (Some (1, 2));
    }
     assert (M.PassCB (10) == 640);
+    
+
+    Bug801.Runner.Go ();
   }
 }
 
@@ -125,5 +159,7 @@
 (foo, bar)
 (3, 4)
 Some ((1, 2))
+42
+OK, got InvalidCast
 END-OUTPUT
 */



More information about the svn mailing list