diff options
author | Dave Mitchell <davem@fdisolutions.com> | 2007-09-10 00:02:55 +0000 |
---|---|---|
committer | Dave Mitchell <davem@fdisolutions.com> | 2007-09-10 00:02:55 +0000 |
commit | 0d3b281c4af2422da931f33692a278c5f05854cf (patch) | |
tree | c9233ce65e6a6e1f741db19d2bb044b4a42f9e0a /t/op/state.t | |
parent | cc4b8646f4297d1d601d9f445953d91eaef16779 (diff) | |
download | perl-0d3b281c4af2422da931f33692a278c5f05854cf.tar.gz |
when anon subs are cloned, the 'assign once only' flag should be
set for all state vars in the pad.
(Nicholas worked up the same fix - spooky action at a distance!)
p4raw-id: //depot/perl@31835
Diffstat (limited to 't/op/state.t')
-rw-r--r-- | t/op/state.t | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/t/op/state.t b/t/op/state.t index c372bf6e12..1c4fc8ca81 100644 --- a/t/op/state.t +++ b/t/op/state.t @@ -10,7 +10,7 @@ BEGIN { use strict; use feature ":5.10"; -plan tests => 119; +plan tests => 123; ok( ! defined state $uninit, q(state vars are undef by default) ); @@ -333,6 +333,21 @@ foreach my $spam (@spam) { is $f[1]->(), 1; } +# each copy of an anon sub should get its own 'once block' + +{ + my $x; # used to force a closure + my @f; + push @f, sub { $x; state $s = $_[0]; $s } for 1..2; + is $f[0]->(1), 1; + is $f[0]->(2), 1; + is $f[1]->(3), 3; + is $f[1]->(4), 3; +} + + + + foreach my $forbidden (<DATA>) { chomp $forbidden; no strict 'vars'; |