preeminent = av_exists(av, idx);
svp = av_fetch(av, idx, 1);
- if (!*svp || *svp == &PL_sv_undef) croak(PL_no_aelem, idx);
+ if (!svp || *svp == &PL_sv_undef) croak(PL_no_aelem, idx);
if (preeminent)
save_aelem(av, idx, svp);
use strict;
use warnings;
-use Test::More tests => 17;
+use Test::More tests => 21;
use Scope::Upper qw/localize_elem/;
is_deeply \@a, [ 4 .. 6 ], 'localize_elem "@a", 4, 8, 0 [end]';
}
+{
+ local @a = (4 .. 6);
+ {
+ localize_elem '@main::a', -2, 8, 0;
+ is_deeply \@a, [ 4, 8, 6 ], 'localize_elem "@a", -2, 8, 0 [ok]';
+ }
+ is_deeply \@a, [ 4 .. 6 ], 'localize_elem "@a", -2, 8, 0 [end]';
+}
+
+{
+ local @a = (4 .. 6);
+ {
+ eval { localize_elem '@main::a', -4, 8, 0 };
+ like $@, qr/Modification of non-creatable array value attempted, subscript -4/, 'localize_elem "@a", -4, 8, 0 [ok]';
+ }
+ is_deeply \@a, [ 4 .. 6 ], 'localize_elem "@a", -4, 8, 0 [end]';
+}
+
{
local @a = (4 .. 6);
{