This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t skip tied EXISTS for negative array indices
authorFather Chrysostomos <sprout@cpan.org>
Sun, 28 Oct 2012 08:44:31 +0000 (01:44 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 28 Oct 2012 09:04:58 +0000 (02:04 -0700)
This was broken in 5.14.0 for those cases where $NEGATIVE_INDICES is
not true:

sub TIEARRAY{bless[]};
sub FETCHSIZE { 50 }
sub EXISTS { print "does $_[1] exist?\n" }
tie @a, "";
exists $a[1];
exists $a[-1];
$NEGATIVE_INDICES=1;
exists $a[-1];

$ pbpaste|perl5.12.0
does 1 exist?
does 49 exist?
does -1 exist?
$ pbpaste|perl5.14.0
does 1 exist?
does -1 exist?

This was broken by 54a4274e3c.

av.c
t/op/tie.t

diff --git a/av.c b/av.c
index b707059..4bdd72d 100644 (file)
--- a/av.c
+++ b/av.c
@@ -968,8 +968,6 @@ Perl_av_exists(pTHX_ AV *av, I32 key)
                     key += AvFILL(av) + 1;
                     if (key < 0)
                         return FALSE;
-                    else
-                        return TRUE;
                 }
             }
 
index 5808a09..83f10dd 100644 (file)
@@ -1302,3 +1302,18 @@ each %$h;
 delete $$h{foo};
 tie %$h, 'l';
 EXPECT
+########
+
+# NAME EXISTS on arrays
+sub TIEARRAY{bless[]};
+sub FETCHSIZE { 50 }
+sub EXISTS { print "does $_[1] exist?\n" }
+tie @a, "";
+exists $a[1];
+exists $a[-1];
+$NEGATIVE_INDICES=1;
+exists $a[-1];
+EXPECT
+does 1 exist?
+does 49 exist?
+does -1 exist?