Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.94k stars 554 forks source link

missing warning #5340

Closed p5pRT closed 14 years ago

p5pRT commented 22 years ago

Migrated from rt.perl.org#8955 (status was 'rejected')

Searchable as RT8955$

p5pRT commented 22 years ago

From @rspier

Why does the first @​{$u} cause a warning (with -w) but the second one doesn't?

$u = undef; @​w = @​{$u}; for (@​{$u}) {};

Use of uninitialized value in array dereference at - line 3.

Seen in perl-current (rc1 to be) and all the way back to 5.005_03\, although the warning may vary.

I started tracking this down (but the email client crashed with an hour worth of notes in it.) I think it's got something to do with the second pp_rv2av op having the OPf_REF flag set\, but the first one doesn't\, probably because of what the for is going to do with it. I tried to track down where it got set\, but it was a twisty twisty maze.

-R (mentioning perl for the bugtron.)

p5pRT commented 14 years ago

From @chorny

Same result on 5.12.0.

On Thu Apr 18 15​:12​:26 2002\, rspier@​pobox.com wrote​:

Why does the first @​{$u} cause a warning (with -w) but the second one doesn't?

$u = undef; @​w = @​{$u}; for (@​{$u}) {};

Use of uninitialized value in array dereference at - line 3.

Seen in perl-current (rc1 to be) and all the way back to 5.005_03\, although the warning may vary.

I started tracking this down (but the email client crashed with an hour worth of notes in it.) I think it's got something to do with the second pp_rv2av op having the OPf_REF flag set\, but the first one doesn't\, probably because of what the for is going to do with it. I tried to track down where it got set\, but it was a twisty twisty maze.

-- Alexandr Ciornii\, http​://chorny.net

p5pRT commented 14 years ago

From [Unknown Contact. See original ticket]

Same result on 5.12.0.

On Thu Apr 18 15​:12​:26 2002\, rspier@​pobox.com wrote​:

Why does the first @​{$u} cause a warning (with -w) but the second one doesn't?

$u = undef; @​w = @​{$u}; for (@​{$u}) {};

Use of uninitialized value in array dereference at - line 3.

Seen in perl-current (rc1 to be) and all the way back to 5.005_03\, although the warning may vary.

I started tracking this down (but the email client crashed with an hour worth of notes in it.) I think it's got something to do with the second pp_rv2av op having the OPf_REF flag set\, but the first one doesn't\, probably because of what the for is going to do with it. I tried to track down where it got set\, but it was a twisty twisty maze.

-- Alexandr Ciornii\, http​://chorny.net

p5pRT commented 14 years ago

From @ikegami

On Thu Apr 18 15​:12​:26 2002\, rspier@​pobox.com wrote​:

Why does the first @​{$u} cause a warning (with -w) but the second one doesn't?

$u = undef; @​w = @​{$u}; for (@​{$u}) {};

When an undefined variable is used in an lvalue deference\, Perl creates the required variable and reference. This is called autovivification.

The first dereference is not an lvalue\, so it warns when the expected reference is missing.

perl -wle"my @​w=@​$u; print $u // '[undef]';" Use of uninitialized value $u in array dereference at -e line 1. [undef]

The second dereference is an lvalue\, so Perl autovivifies $u instead of warning.

perl -wle"1 for @​$u; print $u // '[undef]';" ARRAY(0x248b54)

If you wish to change the behaviour of Perl with respect to autovivification\, use the "autovivification" module on CPAN.

Since lvalue-ness of foreach elements and autovivification are both intentional features\, I'm closing this ticket.

p5pRT commented 14 years ago

@ikegami - Status changed from 'open' to 'rejected'