This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Work around bug 36211, plus a lot of TODO regression tests for local/
authorNicholas Clark <nick@ccl4.org>
Fri, 10 Jun 2005 12:44:30 +0000 (12:44 +0000)
committerNicholas Clark <nick@ccl4.org>
Fri, 10 Jun 2005 12:44:30 +0000 (12:44 +0000)
$#... interaction.

p4raw-id: //depot/perl@24791

scope.c
t/op/array.t

diff --git a/scope.c b/scope.c
index 11c81bd..31a3ebc 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -755,6 +755,9 @@ Perl_leave_scope(pTHX_ I32 base)
            gv = (GV*)SSPOPPTR;
            if (GvAV(gv)) {
                AV * const goner = GvAV(gv);
+               /* FIXME - this is a temporary hack until we work out what
+                  the correct behaviour for magic should be.  */
+               sv_unmagic((SV*)goner, PERL_MAGIC_arylen_p);
                SvMAGIC_set(av, SvMAGIC(goner));
                SvFLAGS((SV*)av) |= SvMAGICAL(goner);
                SvMAGICAL_off(goner);
index 956a934..698d4dc 100755 (executable)
@@ -2,12 +2,12 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = '.', '../lib';
+    @INC = ('.', '../lib');
 }
 
 require 'test.pl';
 
-plan (91);
+plan (111);
 
 #
 # @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them
@@ -294,3 +294,68 @@ sub test_arylen {
     test_arylen ($a);
     test_arylen (do {my @a; \$#a});
 }
+
+{
+    use vars '@array';
+
+    my $outer = \$#array;
+    is ($$outer, -1);
+    is (scalar @array, 0);
+
+    $$outer = 3;
+    is ($$outer, 3);
+    is (scalar @array, 4);
+
+    my $ref = \@array;
+
+    local $TODO = '$#foo semantics with local @foo not fixed yet';
+
+    my $inner;
+    {
+       local @array;
+       $inner = \$#array;
+
+       is ($$inner, -1);
+       is (scalar @array, 0);
+       $$outer = 6;
+
+       is (scalar @$ref, 7);
+
+       is ($$inner, -1);
+       is (scalar @array, 0);
+
+       $$inner = 42;
+    }
+
+    is (scalar @array, 7);
+    is ($$outer, 6);
+
+    is ($$inner, 0, "This is emergent behaviour");
+
+    is (scalar @array, 7);
+    is ($$outer, 6);
+
+    $$inner = 1;
+
+    is (scalar @array, 7);
+    is ($$outer, 6);
+
+    $$inner = 503; # Bang!
+
+    is (scalar @array, 7);
+    is ($$outer, 6);
+}
+
+{
+    # Bug #36211
+    use vars '@array';
+    for (1,2) {
+       {
+           local @a;
+           is ($#a, -1);
+           @a=(1..4)
+       }
+    }
+}
+
+"We're included by lib/Tie/Array/std.t so we need to return something true";