Skip to content

Commit

Permalink
perldelta 4fc2379: make a new stub to clone into when pushing a new pad
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed Feb 21, 2024
1 parent 7f75580 commit 391c8c3
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion pod/perldelta.pod
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,50 @@ manager will later use a regex to expand these into links.

=item *

XXX
Lexical subs now have a new stub in the pad for each recursive call
into the containing function. This fixes two problems:

=over

=item *

If the lexical sub called the containing function, a "Can't undef
active subroutine" error would be thrown. For example:

use v5.36.0;
sub outer($oc) {
my sub inner ($c) {
outer($c-1) if $c; # Can't undef active subroutine
}
inner($oc);
}
outer(2);

[github #18606]

=item *

If the lexical sub was called from a recursive call into the
containing function, this would overwrite the bindings to the closed
over variables in the lexical sub, so calls into the lexical sub from
the outer recursive call would have access to the variables from the
inner recursive call:

use v5.36.0;
sub outer ($x) {
my sub inner ($label) {
say "$label $x";
}
inner("first");
outer("inner") if $x eq "outer";
# this call to inner() sees the wrong $x
inner("second");
}
outer("outer");

[github #21987]

=back

=back

Expand Down

0 comments on commit 391c8c3

Please sign in to comment.