diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-09-14 17:23:11 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-09-14 18:24:21 -0700 |
commit | 429a25554a608b64c0ee46c1ffe19bab3718a3c8 (patch) | |
tree | 14715e2179b09d1708fb9b6bf4516187b225cbe5 /perly.act | |
parent | 61c85d894087ca7f0282600eb64d5af1e7b8e5d4 (diff) | |
download | perl-429a25554a608b64c0ee46c1ffe19bab3718a3c8.tar.gz |
Reduce false positives for @hsh{$s} and @ary[$s] warnings
This resolves tickets #28380 and #114024.
Commit 95a31aad5 did something similar to this for the new %hash{...}
syntax. This commit extends it to @ slices and combines the two
code paths.
The heuristics in toke.c can easily produce false positives. So the
op is flagged as being a candidate for the warning. Then when op.c
has the op tree available, it examines it to see whether the heuristic
may have been a false positive.
This avoids bugs with qw "foo bar baz" and sub calls triggering
the warning.
The source code is no longer available for the warning, so we recon-
struct it from the op tree, skipping the subscript if it is anything
other than a const op.
This means that @hash{$foo} comes out as @hash{...} and @hash{foo} as
@hash{"foo"}. It also meeans that @hash{"]"} is displayed correctly
instead of as @hash{"].
Commit 95a31aad5 also modified the heuristic for %hash{...} to exempt
qw altogether. But it did not exempt it if it was preceded by a tab.
So this commit rectifies that.
This commit also improves the false positive detection by exempting
any ops returning lists that can get past toke.c’s heuristic. I went
through the entire list of ops, but I may have missed some.
Also, @ slices on the lhs of = are exempt, as they change the context
and are hence actually useful.
Diffstat (limited to 'perly.act')
-rw-r--r-- | perly.act | 109 |
1 files changed, 58 insertions, 51 deletions
@@ -1422,13 +1422,16 @@ case 2: newLISTOP(OP_ASLICE, 0, list((ps[(3) - (4)].val.opval)), ref((ps[(1) - (4)].val.opval), OP_ASLICE))); + if ((yyval.opval) && (ps[(1) - (4)].val.opval)) + (yyval.opval)->op_private |= + (ps[(1) - (4)].val.opval)->op_private & OPpSLICEWARNING; TOKEN_GETMAD((ps[(2) - (4)].val.i_tkval),(yyval.opval),'['); TOKEN_GETMAD((ps[(4) - (4)].val.i_tkval),(yyval.opval),']'); ;} break; case 176: -#line 1208 "perly.y" +#line 1211 "perly.y" { (yyval.opval) = op_prepend_elem(OP_KVASLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_KVASLICE, 0, @@ -1443,12 +1446,15 @@ case 2: break; case 177: -#line 1220 "perly.y" +#line 1223 "perly.y" { (yyval.opval) = op_prepend_elem(OP_HSLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_HSLICE, 0, list((ps[(3) - (5)].val.opval)), ref(oopsHV((ps[(1) - (5)].val.opval)), OP_HSLICE))); + if ((yyval.opval) && (ps[(1) - (5)].val.opval)) + (yyval.opval)->op_private |= + (ps[(1) - (5)].val.opval)->op_private & OPpSLICEWARNING; PL_parser->expect = XOPERATOR; TOKEN_GETMAD((ps[(2) - (5)].val.i_tkval),(yyval.opval),'{'); TOKEN_GETMAD((ps[(4) - (5)].val.i_tkval),(yyval.opval),';'); @@ -1457,7 +1463,7 @@ case 2: break; case 178: -#line 1231 "perly.y" +#line 1237 "perly.y" { (yyval.opval) = op_prepend_elem(OP_KVHSLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_KVHSLICE, 0, @@ -1474,17 +1480,17 @@ case 2: break; case 179: -#line 1245 "perly.y" +#line 1251 "perly.y" { (yyval.opval) = (ps[(1) - (1)].val.opval); ;} break; case 180: -#line 1247 "perly.y" +#line 1253 "perly.y" { (yyval.opval) = newUNOP(OP_ENTERSUB, 0, scalar((ps[(1) - (1)].val.opval))); ;} break; case 181: -#line 1249 "perly.y" +#line 1255 "perly.y" { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[(1) - (3)].val.opval))); TOKEN_GETMAD((ps[(2) - (3)].val.i_tkval),(yyval.opval),'('); TOKEN_GETMAD((ps[(3) - (3)].val.i_tkval),(yyval.opval),')'); @@ -1492,7 +1498,7 @@ case 2: break; case 182: -#line 1254 "perly.y" +#line 1260 "perly.y" { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, (ps[(3) - (4)].val.opval), scalar((ps[(1) - (4)].val.opval)))); @@ -1508,7 +1514,7 @@ case 2: break; case 183: -#line 1267 "perly.y" +#line 1273 "perly.y" { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, (ps[(3) - (3)].val.opval), scalar((ps[(2) - (3)].val.opval)))); TOKEN_GETMAD((ps[(1) - (3)].val.i_tkval),(yyval.opval),'o'); @@ -1516,7 +1522,7 @@ case 2: break; case 184: -#line 1272 "perly.y" +#line 1278 "perly.y" { (yyval.opval) = newOP(IVAL((ps[(1) - (1)].val.i_tkval)), OPf_SPECIAL); PL_hints |= HINT_BLOCK_SCOPE; TOKEN_GETMAD((ps[(1) - (1)].val.i_tkval),(yyval.opval),'o'); @@ -1524,74 +1530,74 @@ case 2: break; case 185: -#line 1277 "perly.y" +#line 1283 "perly.y" { (yyval.opval) = newLOOPEX(IVAL((ps[(1) - (2)].val.i_tkval)),(ps[(2) - (2)].val.opval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'o'); ;} break; case 186: -#line 1281 "perly.y" +#line 1287 "perly.y" { (yyval.opval) = newUNOP(OP_NOT, 0, scalar((ps[(2) - (2)].val.opval))); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'o'); ;} break; case 187: -#line 1285 "perly.y" +#line 1291 "perly.y" { (yyval.opval) = newOP(IVAL((ps[(1) - (1)].val.i_tkval)), 0); TOKEN_GETMAD((ps[(1) - (1)].val.i_tkval),(yyval.opval),'o'); ;} break; case 188: -#line 1289 "perly.y" +#line 1295 "perly.y" { (yyval.opval) = newUNOP(IVAL((ps[(1) - (2)].val.i_tkval)), 0, (ps[(2) - (2)].val.opval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'o'); ;} break; case 189: -#line 1293 "perly.y" +#line 1299 "perly.y" { (yyval.opval) = newUNOP(IVAL((ps[(1) - (2)].val.i_tkval)), 0, (ps[(2) - (2)].val.opval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'o'); ;} break; case 190: -#line 1297 "perly.y" +#line 1303 "perly.y" { (yyval.opval) = newOP(OP_REQUIRE, (ps[(1) - (1)].val.i_tkval) ? OPf_SPECIAL : 0); TOKEN_GETMAD((ps[(1) - (1)].val.i_tkval),(yyval.opval),'o'); ;} break; case 191: -#line 1301 "perly.y" +#line 1307 "perly.y" { (yyval.opval) = newUNOP(OP_REQUIRE, (ps[(1) - (2)].val.i_tkval) ? OPf_SPECIAL : 0, (ps[(2) - (2)].val.opval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'o'); ;} break; case 192: -#line 1305 "perly.y" +#line 1311 "perly.y" { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[(1) - (1)].val.opval))); ;} break; case 193: -#line 1307 "perly.y" +#line 1313 "perly.y" { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, (ps[(2) - (2)].val.opval), scalar((ps[(1) - (2)].val.opval)))); ;} break; case 194: -#line 1310 "perly.y" +#line 1316 "perly.y" { (yyval.opval) = newOP(IVAL((ps[(1) - (1)].val.i_tkval)), 0); TOKEN_GETMAD((ps[(1) - (1)].val.i_tkval),(yyval.opval),'o'); ;} break; case 195: -#line 1314 "perly.y" +#line 1320 "perly.y" { (yyval.opval) = newOP(IVAL((ps[(1) - (3)].val.i_tkval)), 0); TOKEN_GETMAD((ps[(1) - (3)].val.i_tkval),(yyval.opval),'o'); TOKEN_GETMAD((ps[(2) - (3)].val.i_tkval),(yyval.opval),'('); @@ -1600,12 +1606,12 @@ case 2: break; case 196: -#line 1320 "perly.y" +#line 1326 "perly.y" { (yyval.opval) = (ps[(1) - (1)].val.opval); ;} break; case 197: -#line 1322 "perly.y" +#line 1328 "perly.y" { (yyval.opval) = (ps[(1) - (3)].val.opval); TOKEN_GETMAD((ps[(2) - (3)].val.i_tkval),(yyval.opval),'('); TOKEN_GETMAD((ps[(3) - (3)].val.i_tkval),(yyval.opval),')'); @@ -1613,13 +1619,13 @@ case 2: break; case 198: -#line 1327 "perly.y" +#line 1333 "perly.y" { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[(1) - (1)].val.opval))); ;} break; case 199: -#line 1330 "perly.y" +#line 1336 "perly.y" { (yyval.opval) = (IVAL((ps[(1) - (3)].val.i_tkval)) == OP_NOT) ? newUNOP(IVAL((ps[(1) - (3)].val.i_tkval)), 0, newSVOP(OP_CONST, 0, newSViv(0))) : newOP(IVAL((ps[(1) - (3)].val.i_tkval)), OPf_SPECIAL); @@ -1631,7 +1637,7 @@ case 2: break; case 200: -#line 1339 "perly.y" +#line 1345 "perly.y" { (yyval.opval) = newUNOP(IVAL((ps[(1) - (4)].val.i_tkval)), 0, (ps[(3) - (4)].val.opval)); TOKEN_GETMAD((ps[(1) - (4)].val.i_tkval),(yyval.opval),'o'); TOKEN_GETMAD((ps[(2) - (4)].val.i_tkval),(yyval.opval),'('); @@ -1640,7 +1646,7 @@ case 2: break; case 201: -#line 1345 "perly.y" +#line 1351 "perly.y" { if ( (ps[(1) - (1)].val.opval)->op_type != OP_TRANS && (ps[(1) - (1)].val.opval)->op_type != OP_TRANSR @@ -1654,7 +1660,7 @@ case 2: break; case 202: -#line 1356 "perly.y" +#line 1362 "perly.y" { (yyval.opval) = pmruntime((ps[(1) - (5)].val.opval), (ps[(4) - (5)].val.opval), 1, (ps[(2) - (5)].val.ival)); TOKEN_GETMAD((ps[(3) - (5)].val.i_tkval),(yyval.opval),'('); TOKEN_GETMAD((ps[(5) - (5)].val.i_tkval),(yyval.opval),')'); @@ -1662,7 +1668,7 @@ case 2: break; case 205: -#line 1363 "perly.y" +#line 1369 "perly.y" { (yyval.opval) = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0), newSVOP(OP_CONST, 0, newSVpvs("Unimplemented"))); @@ -1671,7 +1677,7 @@ case 2: break; case 207: -#line 1373 "perly.y" +#line 1379 "perly.y" { (yyval.opval) = my_attrs((ps[(2) - (3)].val.opval),(ps[(3) - (3)].val.opval)); DO_MAD( token_getmad((ps[(1) - (3)].val.i_tkval),(yyval.opval),'d'); @@ -1682,14 +1688,14 @@ case 2: break; case 208: -#line 1381 "perly.y" +#line 1387 "perly.y" { (yyval.opval) = localize((ps[(2) - (2)].val.opval),IVAL((ps[(1) - (2)].val.i_tkval))); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'d'); ;} break; case 209: -#line 1388 "perly.y" +#line 1394 "perly.y" { (yyval.opval) = sawparens((ps[(2) - (3)].val.opval)); TOKEN_GETMAD((ps[(1) - (3)].val.i_tkval),(yyval.opval),'('); TOKEN_GETMAD((ps[(3) - (3)].val.i_tkval),(yyval.opval),')'); @@ -1697,7 +1703,7 @@ case 2: break; case 210: -#line 1393 "perly.y" +#line 1399 "perly.y" { (yyval.opval) = sawparens(newNULLLIST()); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'('); TOKEN_GETMAD((ps[(2) - (2)].val.i_tkval),(yyval.opval),')'); @@ -1705,68 +1711,69 @@ case 2: break; case 211: -#line 1398 "perly.y" +#line 1404 "perly.y" { (yyval.opval) = (ps[(1) - (1)].val.opval); ;} break; case 212: -#line 1400 "perly.y" +#line 1406 "perly.y" { (yyval.opval) = (ps[(1) - (1)].val.opval); ;} break; case 213: -#line 1402 "perly.y" +#line 1408 "perly.y" { (yyval.opval) = (ps[(1) - (1)].val.opval); ;} break; case 214: -#line 1407 "perly.y" +#line 1413 "perly.y" { (yyval.opval) = (OP*)NULL; ;} break; case 215: -#line 1409 "perly.y" +#line 1415 "perly.y" { (yyval.opval) = (ps[(1) - (1)].val.opval); ;} break; case 216: -#line 1413 "perly.y" +#line 1419 "perly.y" { (yyval.opval) = (OP*)NULL; ;} break; case 217: -#line 1415 "perly.y" +#line 1421 "perly.y" { (yyval.opval) = (ps[(1) - (1)].val.opval); ;} break; case 218: -#line 1421 "perly.y" +#line 1427 "perly.y" { PL_parser->in_my = 0; (yyval.opval) = my((ps[(1) - (1)].val.opval)); ;} break; case 219: -#line 1425 "perly.y" +#line 1431 "perly.y" { (yyval.opval) = newCVREF(IVAL((ps[(1) - (2)].val.i_tkval)),(ps[(2) - (2)].val.opval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'&'); ;} break; case 220: -#line 1431 "perly.y" +#line 1437 "perly.y" { (yyval.opval) = newSVREF((ps[(2) - (2)].val.opval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'$'); ;} break; case 221: -#line 1437 "perly.y" +#line 1443 "perly.y" { (yyval.opval) = newAVREF((ps[(2) - (2)].val.opval)); + if ((yyval.opval)) (yyval.opval)->op_private |= IVAL((ps[(1) - (2)].val.i_tkval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'@'); ;} break; case 222: -#line 1443 "perly.y" +#line 1450 "perly.y" { (yyval.opval) = newHVREF((ps[(2) - (2)].val.opval)); if ((yyval.opval)) (yyval.opval)->op_private |= IVAL((ps[(1) - (2)].val.i_tkval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'%'); @@ -1774,36 +1781,36 @@ case 2: break; case 223: -#line 1450 "perly.y" +#line 1457 "perly.y" { (yyval.opval) = newAVREF((ps[(2) - (2)].val.opval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'l'); ;} break; case 224: -#line 1456 "perly.y" +#line 1463 "perly.y" { (yyval.opval) = newGVREF(0,(ps[(2) - (2)].val.opval)); TOKEN_GETMAD((ps[(1) - (2)].val.i_tkval),(yyval.opval),'*'); ;} break; case 225: -#line 1463 "perly.y" +#line 1470 "perly.y" { (yyval.opval) = scalar((ps[(1) - (1)].val.opval)); ;} break; case 226: -#line 1465 "perly.y" +#line 1472 "perly.y" { (yyval.opval) = scalar((ps[(1) - (1)].val.opval)); ;} break; case 227: -#line 1467 "perly.y" +#line 1474 "perly.y" { (yyval.opval) = op_scope((ps[(1) - (1)].val.opval)); ;} break; case 228: -#line 1470 "perly.y" +#line 1477 "perly.y" { (yyval.opval) = (ps[(1) - (1)].val.opval); ;} break; @@ -1814,6 +1821,6 @@ case 2: /* Generated from: - * 80609b739b642fa427503886445869dfd47021624a1977b902211b38043ed9f1 perly.y + * 5b290f371f373fb17e073f602c676e436e9d457a1d4db67d192e3cfa0eeb36d7 perly.y * 5c9d2a0262457fe9b70073fc8ad6c188f812f38ad57712b7e2f53daa01b297cc regen_perly.pl * ex: set ro: */ |