summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-01-17 19:53:04 +0000
committerDavid Mitchell <davem@iabyn.com>2015-01-17 20:59:33 +0000
commit290c88500428a4387b37a16badfc45a06ab3e83c (patch)
tree4c74bbecf20fe5f1a957c1732f0ef61b4aa86cdb /op.c
parent6bcde12e2f1e7cf9e52bae4dd4e3b833de47f42c (diff)
downloadperl-290c88500428a4387b37a16badfc45a06ab3e83c.tar.gz
avoid $a["foo" eq $x ? 0 : 1] warning
RT #123609 The compiling code that looks for OP_MULTIDEREF candidates was unconditionally numifying the first constant of an array index expression, before it had confirmed that the expression consisted solely of a const. So in something like $a['foo' eq $x ? 0 : 1] the 'foo' would be numified and give a spurious warning: Argument "foo" isn't numeric This commit fixes it by skipping the OP_MULTIDEREF optimisation if the array index const isn't SvIOK(). In theory this means that something like $r->["0"] no longer gets optimised, but I think we can live with that :-) It also means that the test for the const being SvROK is no longer necessary. (Finally, I moved the declaration of the iv var down a few scopes as it wasn't being used elsewhere in the wider scope.)
Diffstat (limited to 'op.c')
-rw-r--r--op.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/op.c b/op.c
index 637a60eee3..c1d41722be 100644
--- a/op.c
+++ b/op.c
@@ -12285,7 +12285,6 @@ S_maybe_multideref(pTHX_ OP *start, OP *orig_o, UV orig_action, U8 hints)
/* look for another (rv2av/hv; get index;
* aelem/helem/exists/delele) sequence */
- IV iv;
OP *kid;
bool is_deref;
bool ok;
@@ -12397,12 +12396,10 @@ S_maybe_multideref(pTHX_ OP *start, OP *orig_o, UV orig_action, U8 hints)
}
else {
/* it's a constant array index */
+ IV iv;
SV *ix_sv = cSVOPo->op_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",
- SVfARG(ix_sv));
+ if (!SvIOK(ix_sv))
+ break;
iv = SvIV(ix_sv);
if ( action_count == 0