summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-11-01 18:25:59 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-11-01 18:50:41 -0700
commit89474f50ca76e8039d27bebe650de4addd0f1607 (patch)
tree632f082b84885242697c056e45080356b11b76e4 /op.c
parentbbdd8bad57f8d77a4e6c3725a49d4d3589efedd7 (diff)
downloadperl-89474f50ca76e8039d27bebe650de4addd0f1607.tar.gz
Warn for $[ ‘version’ checks
Following Michael Schwern’s suggestion, here is a warning for those hapless folks who use $[ for version checks. It applies whenever $[ is used in one of: < > <= >=
Diffstat (limited to 'op.c')
-rw-r--r--op.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/op.c b/op.c
index c34dec5f1c..96efde7686 100644
--- a/op.c
+++ b/op.c
@@ -7284,6 +7284,32 @@ Perl_ck_bitop(pTHX_ OP *o)
return o;
}
+PERL_STATIC_INLINE bool
+is_dollar_bracket(pTHX_ const OP * const o)
+{
+ const OP *kid;
+ return o->op_type == OP_RV2SV && o->op_flags & OPf_KIDS
+ && (kid = cUNOPx(o)->op_first)
+ && kid->op_type == OP_GV
+ && strEQ(GvNAME(cGVOPx_gv(kid)), "[");
+}
+
+OP *
+Perl_ck_cmp(pTHX_ OP *o)
+{
+ PERL_ARGS_ASSERT_CK_CMP;
+ if (ckWARN(WARN_SYNTAX)) {
+ const OP *kid = cUNOPo->op_first;
+ if (kid && (
+ is_dollar_bracket(aTHX_ kid)
+ || ((kid = kid->op_sibling) && is_dollar_bracket(aTHX_ kid))
+ ))
+ Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
+ "$[ used in %s (did you mean $] ?)", OP_DESC(o));
+ }
+ return o;
+}
+
OP *
Perl_ck_concat(pTHX_ OP *o)
{