This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Confused cloning of nested state subs
authorFather Chrysostomos <sprout@cpan.org>
Mon, 12 Jan 2015 04:39:03 +0000 (20:39 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 12 Jan 2015 04:39:03 +0000 (20:39 -0800)
commite0c6a6b8c9a5470601df2e25f77f2422fb3f2ea5
tree5806b0350cb82e32183aaa6d72f3f2217bfaa5ca
parent8a737443e3c53597024b13b97da37ea640b9d851
Confused cloning of nested state subs

use feature 'lexical_subs','state';
no warnings 'experimental';
my $sub = sub{
    state sub sb4;
    state sub a {
        state $x = 42;
        sub sb4 { $x; }
    }
    a();
    print sb4(), "\n";
};
$sub->();

The output:

Bizarre copy of CODE in subroutine exit at - line 10.

The sb4 sub was trying to close over the wrong pad; namely, the one
belonging to the anonymous sub.
pad.c
t/op/lexsub.t