$hashref->{$key} = $value
for ($arrayref->[$idx]) { ... }
for ($hashref->{$key}) { ... }
+ function($arrayref->[$idx])
+ function($hashref->{$key})
An exception is thrown if vivification is needed to store the value, which means that effectively you can only assign to levels that are already defined
In the example, this would require C<$arrayref> (resp. C<$hashref>) to already be an array (resp. hash) reference.
use strict;
use warnings;
-use Test::More tests => 9 * 3 * 290;
+use Test::More tests => 9 * 3 * 302;
use lib 't/lib';
use autovivification::TestCases;
$x->{a} = 1 # 1 for $x->{a}; () # '', undef, { a => 1 } # +store
$x->{a} = 1 # 1 for $x->{b}; () # '', undef, { a => 1, b => undef } # +store
+$x # do_nothing($x->{a}); () # '', undef, { }
+$x # do_nothing($x->{a}); () # '', undef, { } #
+$x # do_nothing($x->{a}); () # '', undef, { } # +fetch
+$x # do_nothing($x->{a}); () # '', undef, { } # +exists
+$x # do_nothing($x->{a}); () # '', undef, { } # +delete
+$x # do_nothing($x->{a}); () # qr/^Can't vivify reference/, undef, undef # +store
+
+$x # set_arg($x->{a}); () # '', undef, { a => 1 }
+$x # set_arg($x->{a}); () # '', undef, { a => 1 } #
+$x # set_arg($x->{a}); () # '', undef, { a => 1 } # +fetch
+$x # set_arg($x->{a}); () # '', undef, { a => 1 } # +exists
+$x # set_arg($x->{a}); () # '', undef, { a => 1 } # +delete
+$x # set_arg($x->{a}); () # qr/^Can't vivify reference/, undef, undef # +store
+
--- dereferencing ---
$x # no warnings 'uninitialized'; my @a = %$x; () # ($strict ? qr/^Can't use an undefined value as a HASH reference/ : ''), undef, undef
use strict;
use warnings;
-use Test::More tests => 9 * 3 * 290;
+use Test::More tests => 9 * 3 * 302;
use lib 't/lib';
use autovivification::TestCases;
$x->[$N[0]] = 1 # 1 for $x->[$N[0]]; () # '', undef, [ 1 ] # +store
$x->[$N[0]] = 1 # 1 for $x->[$N[1]]; () # '', undef, [ 1, undef ] # +store
+$x # do_nothing($x->[$N[0]]); () # '', undef, [ ]
+$x # do_nothing($x->[$N[0]]); () # '', undef, [ ] #
+$x # do_nothing($x->[$N[0]]); () # '', undef, [ ] # +fetch
+$x # do_nothing($x->[$N[0]]); () # '', undef, [ ] # +exists
+$x # do_nothing($x->[$N[0]]); () # '', undef, [ ] # +delete
+$x # do_nothing($x->[$N[0]]); () # qr/^Can't vivify reference/, undef, undef # +store
+
+$x # set_arg($x->[$N[0]]); () # '', undef, [ 1 ]
+$x # set_arg($x->[$N[0]]); () # '', undef, [ 1 ] #
+$x # set_arg($x->[$N[0]]); () # '', undef, [ 1 ] # +fetch
+$x # set_arg($x->[$N[0]]); () # '', undef, [ 1 ] # +exists
+$x # set_arg($x->[$N[0]]); () # '', undef, [ 1 ] # +delete
+$x # set_arg($x->[$N[0]]); () # qr/^Can't vivify reference/, undef, undef # +store
+
--- dereferencing ---
$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/^Can't use an undefined value as an ARRAY reference/ : ''), undef, undef
use strict;
use warnings;
-use Test::More tests => 9 * 3 * 290;
+use Test::More tests => 9 * 3 * 302;
use lib 't/lib';
use autovivification::TestCases;
$x->[0] = 1 # 1 for $x->[0]; () # '', undef, [ 1 ] # +store
$x->[0] = 1 # 1 for $x->[1]; () # '', undef, [ 1, undef ] # +store
+$x # do_nothing($x->[0]); () # '', undef, [ ]
+$x # do_nothing($x->[0]); () # '', undef, [ ] #
+$x # do_nothing($x->[0]); () # '', undef, [ ] # +fetch
+$x # do_nothing($x->[0]); () # '', undef, [ ] # +exists
+$x # do_nothing($x->[0]); () # '', undef, [ ] # +delete
+$x # do_nothing($x->[0]); () # qr/^Can't vivify reference/, undef, undef # +store
+
+$x # set_arg($x->[0]); () # '', undef, [ 1 ]
+$x # set_arg($x->[0]); () # '', undef, [ 1 ] #
+$x # set_arg($x->[0]); () # '', undef, [ 1 ] # +fetch
+$x # set_arg($x->[0]); () # '', undef, [ 1 ] # +exists
+$x # set_arg($x->[0]); () # '', undef, [ 1 ] # +delete
+$x # set_arg($x->[0]); () # qr/^Can't vivify reference/, undef, undef # +store
+
--- dereferencing ---
$x # no warnings 'uninitialized'; my @a = @$x; () # ($strict ? qr/^Can't use an undefined value as an ARRAY reference/ : ''), undef, undef
sub in_strict { (caller 0)[8] & (eval { strict::bits(@_) } || 0) };
+sub do_nothing { }
+
+sub set_arg { $_[0] = 1 }
+
sub generate {
my ($var, $init, $code, $exp, $use, $opts, $global) = @_;
my $decl = $global ? "our $var; local $var;" : "my $var;";