[perl #79908] Stop sub inlining from breaking closures
authorFather Chrysostomos <sprout@cpan.org>
Mon, 1 Jul 2013 03:26:34 +0000 (20:26 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 26 Jul 2013 06:48:02 +0000 (23:48 -0700)
commit137da2b05b4b7628115049f343163bdaf2c30dbb
treef67f94858229947447c68a9676d49af49c593d4b
parentd2440203227a535b62a2078d898d0bd993ceac78
[perl #79908] Stop sub inlining from breaking closures

When a closure closes over a variable, it references the variable
itself, as opposed to taking a snapshot of its value.

This was broken by the constant optimisation added for
constant.pm’s sake:

{
    my $x;
    sub () { $x };  # takes a snapshot of the current value of $x
}

constant.pm no longer uses that mechanism, except on older perls, so
we can remove this hack, causing code like this this to start work-
ing again:

BEGIN{
    my $x = 5;
    *foo = sub(){$x};
    $x = 6
}
print foo; # now prints 6, not 5
embed.fnc
embed.h
op.c
pad.c
proto.h
t/op/sub.t