This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fewer false positives for %hash{$scalar} warning
authorFather Chrysostomos <sprout@cpan.org>
Thu, 12 Sep 2013 21:30:41 +0000 (14:30 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 13 Sep 2013 08:25:36 +0000 (01:25 -0700)
commit95a31aad58c629646a232acf2fdd010a10b1b9b5
treea037675ea63340540ad63ea11a8f8244d7817884
parentadad97db02f9834fe787095ccf3593bf7f8d666c
Fewer false positives for %hash{$scalar} warning

Instead of warning in the lexer, flag the op and then warn in op.c,
when the op tree is available, so we don’t end up warning for actual
lists or for sub calls.

Also, only warn in scalar context, as in list context $hash{$scalar}
and %hash{$scalar} do different things.

In op.c we no longer have easy access to the source code, so recon-
struct the hash/array access based on the op tree.  This means
%hash{foo} becomes %hash{"foo"}.  We only reconstruct constant keys,
so %hash{++$x} becomes %hash{...}.  This also corrects erroneous
dumps, like %hash{"} for %hash{"}"}.

Instead of triggering the warning solely based on the op tree, we
still keep the heuristic in toke.c, so that common workarounds for
that warning (e.g., {q<key>} and {("key")}) continue to work.

The heuristic in toke.c is tweaked to avoid warning for qw().

In a future commit I plan to extend this to the existing @array[0] and
@hash{key} warnings, to avoid false positives.
dump.c
ext/B/B/Concise.pm
op.c
op.h
perly.act
perly.h
perly.tab
perly.y
t/op/kvaslice.t
t/op/kvhslice.t
toke.c