Skip to content
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

Error with prototypes #33

Open
tobyink opened this issue Jan 9, 2021 · 1 comment
Open

Error with prototypes #33

tobyink opened this issue Jan 9, 2021 · 1 comment

Comments

@tobyink
Copy link
Owner

tobyink commented Jan 9, 2021

Migrated from rt.cpan.org #97875 (status was 'open')

Requestors:

From [email protected] on 2014-08-08 12:31:35
:

On Kavorka-0.030 and Perl 5.20 (Linux debian 3.2.0-4-686-pae #1 SMP Debian 3.2.60-1+deb7u1 i686 GNU/Linux) I get the error
Variable "$x" is not available at test.pl line 17
when executing the code:
use v5.14;use warnings;use Kavorka;
my $tf = sub { 1;};
sub test (&){ $[0];}
my $a = test { my $x = $tf->(); fun(){ $x+$
[0]; }};
It works if sub is used instead of fun(). I'm not sure why this particular case should fail.

@tobyink
Copy link
Owner Author

tobyink commented Jan 9, 2021

From [email protected] on 2017-01-31 17:53:11
:

Fun. I guess it's having trouble closing over $x for some reason.

Bizarre though because this works fine:

use v5.14;
use warnings;
use Kavorka;
sub test (&) { $[0] }
my $a = test {
my $x = 1;
fun { $x+$
[0] }
};

I think in that case, $x is known to be 1, so gets optimized away within the function and is never really closed over.

It's strange though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant