[svn:parrot] r45274 - in trunk: src t/pmc

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Mon Mar 29 13:16:29 UTC 2010


Author: whiteknight
Date: Mon Mar 29 13:16:28 2010
New Revision: 45274
URL: https://trac.parrot.org/parrot/changeset/45274

Log:
[TT #1133] Fixed the manhattan distance calculation so that primitive types are treated as properly autoboxing, and allow the MRO of the autoboxed type to be walked. Added a test case to prove TT #1133 is satisfied, though the test is in perl and that makes whiteknight sad. This should resolve TT #1133.

Modified:
   trunk/src/multidispatch.c
   trunk/t/pmc/multidispatch.t

Modified: trunk/src/multidispatch.c
==============================================================================
--- trunk/src/multidispatch.c	Mon Mar 29 12:28:36 2010	(r45273)
+++ trunk/src/multidispatch.c	Mon Mar 29 13:16:28 2010	(r45274)
@@ -634,7 +634,7 @@
     /* now go through args */
     for (i = 0; i < n; ++i) {
         const INTVAL type_sig  = VTABLE_get_integer_keyed_int(interp, multi_sig, i);
-        const INTVAL type_call = VTABLE_get_integer_keyed_int(interp, arg_tuple, i);
+        INTVAL type_call = VTABLE_get_integer_keyed_int(interp, arg_tuple, i);
         if (type_sig == type_call)
             continue;
 
@@ -647,15 +647,27 @@
         switch (type_call) {
           case enum_type_INTVAL:
             if (type_sig == enum_class_Integer) { dist++; continue; }
-            if (type_sig == enum_type_PMC) dist++;
+            if (type_sig == enum_type_PMC ||
+                (type_sig >= enum_class_default && type_sig < enum_class_core_max)) {
+                dist++;
+                type_call = enum_class_Integer;
+            }
             break;
           case enum_type_FLOATVAL:
             if (type_sig == enum_class_Float)   { dist++; continue; }
-            if (type_sig == enum_type_PMC) dist++;
+            if (type_sig == enum_type_PMC ||
+                (type_sig >= enum_class_default && type_sig < enum_class_core_max)) {
+                dist++;
+                type_call = enum_class_Float;
+            }
             break;
           case enum_type_STRING:
             if (type_sig == enum_class_String)  { dist++; continue; }
-            if (type_sig == enum_type_PMC) dist++;
+            if (type_sig == enum_type_PMC ||
+                (type_sig >= enum_class_default && type_sig < enum_class_core_max)) {
+                dist++;
+                type_call = enum_class_String;
+            }
             break;
           default:
             break;

Modified: trunk/t/pmc/multidispatch.t
==============================================================================
--- trunk/t/pmc/multidispatch.t	Mon Mar 29 12:28:36 2010	(r45273)
+++ trunk/t/pmc/multidispatch.t	Mon Mar 29 13:16:28 2010	(r45274)
@@ -9,7 +9,7 @@
 use Test::More;
 use Parrot::Test::Util 'create_tempfile';
 
-use Parrot::Test tests => 46;
+use Parrot::Test tests => 47;
 
 =head1 NAME
 
@@ -1516,6 +1516,30 @@
 1
 OUTPUT
 
+pir_output_is( <<'CODE', <<'OUTPUT', 'int autoboxes to scalar - TT #1133' );
+    .sub 'foo' :multi(['scalar'])
+        .param pmc x
+        say "Scalar!"
+    .end
+
+    .sub 'foo' :multi()
+        .param pmc x
+        $I0 = isa x, 'scalar'
+        print "Scalar? "
+        say $I0
+    .end
+
+    .sub 'main' :main
+        'foo'(1)
+        $P0 = box 1
+        'foo'($P0)
+    .end
+CODE
+Scalar!
+Scalar!
+OUTPUT
+
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4


More information about the parrot-commits mailing list