Bug 846330

Summary: Lexical subroutines make some variables unavailable
Product: [Fedora] Fedora Reporter: Petr Pisar <ppisar>
Component: perlAssignee: Marcela Mašláňová <mmaslano>
Status: CLOSED CANTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 17CC: cweyl, iarnell, jplesnik, kasal, lkundrak, mmaslano, perl-devel, ppisar, psabata, rc040203, tcallawa
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
URL: https://rt.perl.org/rt3//Public/Bug/Display.html?id=113930
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-09-11 12:01:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Petr Pisar 2012-08-07 13:25:34 UTC
This code:

sub foo {
    my $x if @_;
    return if @_;

    $x = 17;
    print $x, "\n";
    print sub { $x }->(), "\n";
    return;

}
foo(1); # make $x stale in all perl versions
foo;

produces errors and wrong output because it stales the $x:

17
Variable "$x" is not available at ./lexical_sub line 11.
Use of uninitialized value in print at ./lexical_sub line 11.


All perls since 5.10.1 are affected.

All Fedoras are affected.

Fixed in upstream by commit:

commit cae5dbbe30ba4a96ff5e570be0d90779f06fee71
Author: Father Chrysostomos <sprout>
Date:   Sat Aug 4 14:42:47 2012 -0700

    Close over stale vars in active subs

Comment 1 Petr Pisar 2012-09-11 11:06:44 UTC
This alone patch applied to 5.16.1 causes failures in t/op/closure.t. This patch pre-requires other patches. And actually lexical subroutines are experimental and upstream has not resolved all problems yet.

Comment 2 Petr Pisar 2012-09-11 12:01:25 UTC
I ported five other patches and it still needs other ones. They change internals of cloning contexts and opens series of another mistakes. This bug reports is not resolvable now. It will be fixed in next perl minior version (5.18).