Skip to content

Commit

Permalink
fix spurious 'Use of reference' warning
Browse files Browse the repository at this point in the history
My recent OP_MULTIDEREF addition introduced a bug where, when
converting a constant array index into a UV, it checked for a ref
and issued a "Use of reference "HASH(0x7fd190915ba8)" as array index"
warning *before* it had confirmed that the OP_CONST was the only op in
the index expression. So things like

    use constant HASHREF => { a => 1 };
    () = $_[HASHREF->{a} ];

would generate two spurious warnings.

The fix is easy. Only test for the warning on the second pass;
we'll already have abandoned the optimisation attempt on the first pass
if the index expression isn't a simple constant.
  • Loading branch information
iabyn committed Dec 10, 2014
1 parent dacd918 commit b48c4cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion op.c
Expand Up @@ -12398,7 +12398,7 @@ S_maybe_multideref(pTHX_ OP *start, OP *orig_o, UV orig_action, U8 hints)
else {
/* it's a constant array index */
SV *ix_sv = cSVOPo->op_sv;
if (UNLIKELY(SvROK(ix_sv) && !SvGAMAGIC(ix_sv)
if (pass && UNLIKELY(SvROK(ix_sv) && !SvGAMAGIC(ix_sv)
&& ckWARN(WARN_MISC)))
Perl_warner(aTHX_ packWARN(WARN_MISC),
"Use of reference \"%"SVf"\" as array index",
Expand Down
14 changes: 14 additions & 0 deletions t/lib/warnings/pp_hot
Expand Up @@ -343,3 +343,17 @@ print $x[$b];
EXPECT
OPTION regex
Use of reference ".*" as array index at - line 7.
########
use warnings 'misc';
use constant FOO => { a => 1 };
() = $_[FOO->{a}];

EXPECT
########
use warnings 'misc';
use constant FOO => {};
() = $_[FOO];

EXPECT
OPTION regex
Use of reference "HASH\(0x\w+\)" as array index at - line 3.

0 comments on commit b48c4cb

Please sign in to comment.