# New Ticket Created by  Bram Geron 
# Please include the string:  [perl #44471]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=44471 >


:vtable subs are not stored in the vtable slot of a namespace when :anon
is set. This is because :anon blocks the sub from reaching the namespace:

src/global.c: (Parrot_store_sub_in_namespace)
    613     else if (!(PObj_get_FLAGS(sub) & SUB_FLAG_PF_ANON)) {
    ...         ...
    617         Parrot_store_global_n(interp, ns, name, sub);

Parrot_store_global_n calls namespace->set_pmc_keyed_str, which also
checks if subs are :anon, so the check in Parrot_store_sub_in_namespace
seems to be unnecessary. If we remove it, :vtable :anon works.

This patch removes the check in Parrot_store_sub_in_namespace, and
there's a test too. Created t/compilers/imcc/syn/sub.t for that.

 src/global.c               |    5 +++--
 t/compilers/imcc/syn/sub.t |   36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)

-- 
Bram Geron | GPG 0xE7B9E65E


diff --git a/src/global.c b/src/global.c
index 29b9b30..fe4bf75 100644
--- a/src/global.c
+++ b/src/global.c
@@ -609,8 +609,9 @@ Parrot_store_sub_in_namespace(PARROT_INTERP, NOTNULL(PMC *sub))
     /* store a :multi sub */
     if (!PMC_IS_NULL(PMC_sub(sub)->multi_signature))
         store_sub_in_multi(interp, sub, ns);
-    /* store other subs (as long as they're not :anon) */
-    else if (!(PObj_get_FLAGS(sub) & SUB_FLAG_PF_ANON)) {
+    /* store other subs (as long as they're not :anon, but the namespace will
+     * detect that) */
+    else {
         STRING * const name   = PMC_sub(sub)->name;
         PMC    * const nsname = PMC_sub(sub)->namespace_name;
 
diff --git a/t/compilers/imcc/syn/sub.t b/t/compilers/imcc/syn/sub.t
new file mode 100644
index 0000000..91bc06e
--- /dev/null
+++ b/t/compilers/imcc/syn/sub.t
@@ -0,0 +1,36 @@
+#!perl
+# Copyright (C) 2005, The Perl Foundation.
+# $Id$
+
+use strict;
+use warnings;
+use lib qw( . lib ../lib ../../lib );
+use Parrot::Test tests => 1;
+
+##############################
+
+pir_output_is( <<'CODE', <<'OUTPUT', ":anon :vtable should work" );
+.sub main :main
+    $P0 = newclass "Foo"
+    $P0 = new "Foo"
+    $I0 = $P0
+    $S0 = $I0
+    say $S0
+.end
+
+.namespace ["Foo"]
+
+.sub get_integer :vtable :anon
+    .return (42)
+.end
+CODE
+42
+OUTPUT
+
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:


Reply via email to