Subject: | Named parameters cause lexical scoping problems with Try::Tiny |
I don't know if this is a Try::Tiny issue, but the following code fails.
func named_params(:$a) {
my $b;
try { die $a }
catch { $b = $_ };
return $b; #<---- $b is undef here
}
Also, this warning is issued:
Aliasing of outer lexical variable has limited scope
The bug only happens with named parameters & try/catch. The same code
works with positional parameters are used, or dropping try/catch for
plain eval.
Attached is a small test case.
git bisecting with this test points to this commit:
https://github.com/schwern/method-signatures/commit/6f353069833dd6febab6c11cc9613f3204d63d32
Subject: | aliasing-outer-lexical.t |
use strict;
use warnings;
use Test::More;
use Method::Signatures;
use Try::Tiny;
func positional_params($a) {
my $b;
try { die $a }
catch { $b = $_ };
return $b;
}
func named_params(:$a) {
my $b;
try { die $a }
catch { $b = $_ };
return $b;
}
func named_params_eval(:$a) {
my $b;
eval { die $a };
if ($@) { $b = $@ }
return $b;
}
my $arg = {};
is( positional_params($arg), $arg, 'try/catch with positional params');
is( named_params(a => $arg), $arg, 'try/catch with named params');
is( named_params_eval(a => $arg), $arg , 'eval with named params');
done_testing();