diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-11-01 18:25:59 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-11-01 18:50:41 -0700 |
commit | 89474f50ca76e8039d27bebe650de4addd0f1607 (patch) | |
tree | 632f082b84885242697c056e45080356b11b76e4 /op.c | |
parent | bbdd8bad57f8d77a4e6c3725a49d4d3589efedd7 (diff) | |
download | perl-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.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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) { |