New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable "$x" is not available triggered by lexical subs #15471
Comments
From @maukeCreated by @mauke$ perl -wE 'use experimental "lexical_subs"; my sub foo; sub bar { my ($x) = @_; sub foo { $x } }' According to perldoc perldiag, 'Variable "%s" is not available' only happens Perl Info
|
From @cpansproutOn Sat Jul 23 15:29:46 2016, mauke- wrote:
Should it be producing that warning, or should it producing this one? $ ./perl -Ilib -wE 'sub bar { my ($x) = @_; sub foo { $x } }' With regard to the implementation, lexical subs are comparable to this example given in perldiag: sub f { Conceptually, they have more in common with the ‘not stay shared’ example. Both of these warnings sort of fall out of the implementation, and are just there to warn the programmer that things may not behave as intended, for non-obvious reasons. I’m ambivalent about how we should resolve this. Either we expand the ‘not available’ documentation in perldiag, or we change it to the other warning. Which should it be? -- Father Chrysostomos |
The RT System itself - Status changed from 'new' to 'open' |
From @ap* Father Chrysostomos via RT <perlbug-followup@perl.org> [2016-07-24 07:24]:
As I understand the “not available” warning, it really only talks about If I am correct then I say it ought to warn “will not stay shared”. Regards, |
From @cpansproutOn Sat Jul 30 20:46:25 2016, aristotle wrote:
It can mean ‘not available ever’: sub { ‘Is not available’ means ‘we are creating a sub right now, but we can’t get the value from that outside variable.’ (Though, come to think of it, ‘will not stay shared’ means the same thing. Maybe I should actually look at the code, instead of waving my hands so frantically. :-)
Those last eight words were want I wanted to hear.
Based on your feedback, I agree. Thank you. -- Father Chrysostomos |
From @iabynOn Sat, Jul 30, 2016 at 11:15:43PM -0700, Father Chrysostomos via RT wrote:
'not available' and 'not stay shared' are two different things. This: sub bar { bar(1); gives: Variable "$x" will not stay shared at /home/davem/tmp/p line 7. i.e. the $x captured by foo() always remains as the first instance of Prepending this to the above example: my sub foo; gives: Variable "$x" is not available. I don't know enough of the details of lexical vars to know whether that's -- |
From @cpansproutOn Thu Aug 04 04:07:17 2016, davem wrote:
I am slightly surprised that the output is different. It may even be a bug, but in such areas the implementation usually gets to decide the correct behaviour. ‘my’ subs are cloned when the scope in which the declaration occurs is entered. So the lexical sub case is similar to the package sub case, in that the inner sub is created before the outer sub is called. But ‘my’ subs follow a different code path (the same code that clones anonymous subs) from package subs. So now the question is whether those code paths should be doing the same thing. As usual, I’m too lazy to look at the code right now, so this conversation will probably go nowhere, at least for the time being. -- Father Chrysostomos |
From @iabynOn Sat, Aug 06, 2016 at 07:45:22PM -0700, Father Chrysostomos via RT wrote:
Ok, given that foo is cloned near the start of execution, after bar -- |
Migrated from rt.perl.org#128709 (status was 'open')
Searchable as RT128709$
The text was updated successfully, but these errors were encountered: