Open Azq2 opened 1 year ago
I suspect this ticket should get the "my-in-false-conditional" label. Can someone confirm that?
I suspect this ticket should get the "my-in-false-conditional" label. Can someone confirm that?
Sure. Hmm... This is a known bug since 2003... 😱
my if
is explicitly documented as undefined behaviour.
To be specific, you're not allowed to use a variable without first running the my
.
No, it's not a global var.
$ perl -e'
use feature qw( say );
sub f {
my $false = undef;
my $v if $false;
$v = $_[0] if @_;
$v
}
$v = 123;
say $v;
say f( "abc" );
say f();
say f( "def" );
say f();
say $v;
'
123
abc
abc
def
def
123
It's still a lexically-scoped var, but it doesn't get cleared properly because the my
didn't get executed.
Code:
Description When $cond is "constant false" then the perl bytecode optimizer removes dead code
my $v = 99999 if $cond;
, but even withmy $v
statement.After this
$v
goes into a global variable!Steps to Reproduce Just run the code.
Expected behavior Optimizer must not remove the
my $v
part in this expression.Perl configuration