# New Ticket Created by Patrick R. Michaud
# Please include the string: [perl #56398]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56398 >
Earlier today Jonathan was able to implement the :lexid proposal
discussed in RT#56274. We've now run into another problem or bug.
I'll demonstrate with code. First, here's the Perl 6 version
of what we're trying to do:
foo('try 1');
foo('try 2');
foo('try 3');
sub foo($x) {
say "outer foo $x";
{
say "inner foo $x";
$x := 'BOGUS!';
}
}
The C<foo> subroutine contains a nested immediate block that
prints the contents of C<$x> from its outer scope, then rebinds
<$x> to a new value.
Here's the PIR version of the above:
.sub 'main' :main
foo('try 1')
foo('try 2')
foo('try 3')
.end
.sub 'foo' :lexid('foo')
.param pmc x
.lex '$x', x
print "outer foo "
say x
'inner'()
.end
.sub 'inner' :outer('foo')
.local pmc x
x = find_lex '$x'
print "inner foo "
say x
$P0 = new 'String'
$P0 = 'BOGUS!'
store_lex '$x', $P0
.end
And here's what happens when we run it:
$ ./parrot badlex.pir
outer foo try 1
inner foo try 1
outer foo try 2
inner foo BOGUS!
outer foo try 3
inner foo BOGUS!
$
The first call to foo() works. In the second and subsequent
calls to foo(), execution of the inner-scoped immediate block
still refers to the lexpad that was established during the
first call to C<foo>, as opposed to the lexpads creating for
the later calls.
Pm