On Thu, May 10, 2012 at 02:27:05PM +0100, Nicholas Clark wrote:
> On Tue, Sep 06, 2011 at 12:29:00PM +0100, Dave Mitchell wrote:
>
> > There is a second issue that is brought up by the original bug report,
> > and that is that $a =~ /foo/ closes over any outer lexical $_, even though
> > it doesn't use $_. This is because when /foo/ is compiled, it initially
> > assumes that it wants to use $_ and so closes over it (if there's a lexical
> > version in scope); only later does it see the =~ bind operator, and
> > undo that assumption (by setting OPf_STACKED). By then the closure
> > has already been set up (a FAKE entry in the pad).
> >
> > I don't see a simple way to fix that.
>
> Meaning that the third section of this code is buggy?
[snip]
> sub buggy {
> my $_ = shift;
> return sub {
> my $m = "I'm not to be a closure\n";
> $m =~ s/not/not meant/;
> print $m;
> }
> }
[snip]
> print "Should not close either\n";
> $s = buggy(bless []);
> print "(object should be gone)\n";
> $s->();
> undef $s;
>
> __END__
> $ ./perl -Ilib ../test/94682.pl
[snip]
> Should not close either
> (object should be gone)
> I'm not meant to be a closure
> DESTROY for main=ARRAY(0x1008114c0)
>
>
> In that the sub buggy() should not return a closure, hence the third
> paragraph of output should be the same as the second, not the first, as
> currently is?
Correct.
>
> (and this should become a TODO test somewhere?)
Yes. op/closure.t ???
--
"I do not resent criticism, even when, for the sake of emphasis,
it parts for the time with reality".
-- Winston Churchill, House of Commons, 22nd Jan 1941.
Thread Previous