summaryrefslogtreecommitdiff
path: root/perly.tab
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2018-02-26 18:52:23 +0000
committerDavid Mitchell <davem@iabyn.com>2018-03-02 13:36:43 +0000
commita8c5635617479436b1775ba4ab34e4bc791eda54 (patch)
tree870dda66a262326c7e359e6c8fd7d45383b39867 /perly.tab
parent86ae8d9a6f56e9e71efc1f3e556f6770dc07566e (diff)
downloadperl-a8c5635617479436b1775ba4ab34e4bc791eda54.tar.gz
detect sub attributes following a signature
RT #132760 A recent commit (v5.27.7-212-g894f226) moved subroutine attributes back before the subroutine's signature: e.g. sub foo :prototype($$) ($a, $b) { ... } # 5.18 and 5.28 + sub foo ($a, $b) :prototype($$) { ... } # 5.20 .. 5.26 This change means that any code still using an attribute following the signature is going to trigger a syntax error. However, the error, followed by error recovery and further warnings and errors, is very unfriendly and gives no indication of the root cause. This commit introduces a new error, "Subroutine attributes must come before the signature". For example, List::Lazy, the subject of the ticket, failed to compile tests, with output like: Array found where operator expected at blib/lib/List/Lazy.pm line 43, near "$$@)" (Missing operator before @)?) "my" variable $step masks earlier declaration in same statement at blib/lib/List/Lazy.pm line 44. syntax error at blib/lib/List/Lazy.pm line 36, near ") :" Global symbol "$generator" requires explicit package name (did you forget to declare "my $generator"?) at blib/lib/List/Lazy.pm line 38. Global symbol "$state" requires explicit package name (did you forget to declare "my $state"?) at blib/lib/List/Lazy.pm line 39. Global symbol "$min" requires explicit package name (did you forget to declare "my $min"?) at blib/lib/List/Lazy.pm line 43. Global symbol "$max" requires explicit package name (did you forget to declare "my $max"?) at blib/lib/List/Lazy.pm line 43. Global symbol "$step" requires explicit package name (did you forget to declare "my $step"?) at blib/lib/List/Lazy.pm line 43. Invalid separator character '{' in attribute list at blib/lib/List/Lazy.pm line 44, near "$step : sub " Global symbol "$step" requires explicit package name (did you forget to declare "my $step"?) at blib/lib/List/Lazy.pm line 44. But following this commit, it now just outputs: Subroutine attributes must come before the signature at blib/lib/List/Lazy.pm line 36. Compilation failed in require at t/append.t line 5. BEGIN failed--compilation aborted at t/append.t line 5. It works by: 1) adding a boolean flag (sig_seen) to the parser state to indicate that a signature has been parsed; 2) at the end of parsing a signature, PL_expect is set to XATTRBLOCK rather than XBLOCK. Then if something looking like one or more attributes is encountered by the lexer immediately afterwards, it scans it as if it were an attribute, but then if sig_seen is true, it croaks.
Diffstat (limited to 'perly.tab')
-rw-r--r--perly.tab36
1 files changed, 18 insertions, 18 deletions
diff --git a/perly.tab b/perly.tab
index db040cdae3..d918aa6670 100644
--- a/perly.tab
+++ b/perly.tab
@@ -80,23 +80,23 @@ static const yytype_uint16 yyrline[] =
559, 563, 567, 568, 572, 578, 583, 588, 589, 594,
595, 600, 601, 603, 608, 610, 622, 623, 628, 630,
634, 654, 655, 657, 663, 728, 730, 736, 738, 742,
- 748, 749, 754, 755, 760, 759, 809, 810, 815, 826,
- 827, 830, 841, 843, 845, 847, 851, 853, 858, 862,
- 866, 870, 876, 881, 887, 893, 895, 898, 897, 908,
- 909, 913, 917, 920, 925, 930, 933, 937, 941, 947,
- 955, 962, 968, 970, 972, 977, 979, 981, 986, 988,
- 990, 992, 994, 996, 998, 1000, 1002, 1004, 1006, 1011,
- 1013, 1016, 1018, 1020, 1023, 1026, 1037, 1040, 1047, 1049,
- 1051, 1053, 1055, 1058, 1064, 1066, 1070, 1071, 1072, 1073,
- 1074, 1076, 1078, 1080, 1082, 1084, 1086, 1088, 1090, 1092,
- 1094, 1096, 1098, 1100, 1102, 1112, 1122, 1132, 1142, 1144,
- 1146, 1149, 1154, 1158, 1160, 1162, 1164, 1167, 1169, 1172,
- 1174, 1176, 1178, 1180, 1182, 1184, 1186, 1188, 1191, 1193,
- 1195, 1197, 1199, 1201, 1205, 1208, 1207, 1220, 1221, 1222,
- 1226, 1228, 1230, 1235, 1237, 1240, 1242, 1244, 1249, 1251,
- 1256, 1257, 1262, 1263, 1269, 1273, 1274, 1275, 1278, 1279,
- 1282, 1283, 1286, 1290, 1294, 1300, 1306, 1308, 1312, 1316,
- 1317, 1321, 1322, 1326, 1327, 1332, 1334, 1336, 1339
+ 748, 749, 754, 755, 760, 759, 818, 819, 824, 835,
+ 836, 839, 850, 852, 854, 856, 860, 862, 867, 871,
+ 875, 879, 885, 890, 896, 902, 904, 907, 906, 917,
+ 918, 922, 926, 929, 934, 939, 942, 946, 950, 956,
+ 964, 971, 977, 979, 981, 986, 988, 990, 995, 997,
+ 999, 1001, 1003, 1005, 1007, 1009, 1011, 1013, 1015, 1020,
+ 1022, 1025, 1027, 1029, 1032, 1035, 1046, 1049, 1056, 1058,
+ 1060, 1062, 1064, 1067, 1073, 1075, 1079, 1080, 1081, 1082,
+ 1083, 1085, 1087, 1089, 1091, 1093, 1095, 1097, 1099, 1101,
+ 1103, 1105, 1107, 1109, 1111, 1121, 1131, 1141, 1151, 1153,
+ 1155, 1158, 1163, 1167, 1169, 1171, 1173, 1176, 1178, 1181,
+ 1183, 1185, 1187, 1189, 1191, 1193, 1195, 1197, 1200, 1202,
+ 1204, 1206, 1208, 1210, 1214, 1217, 1216, 1229, 1230, 1231,
+ 1235, 1237, 1239, 1244, 1246, 1249, 1251, 1253, 1258, 1260,
+ 1265, 1266, 1271, 1272, 1278, 1282, 1283, 1284, 1287, 1288,
+ 1291, 1292, 1295, 1299, 1303, 1309, 1315, 1317, 1321, 1325,
+ 1326, 1330, 1331, 1335, 1336, 1341, 1343, 1345, 1348
};
#endif
@@ -1130,6 +1130,6 @@ static const toketypes yy_type_tab[] =
};
/* Generated from:
- * 1464f62136e1c8980247e644a1b280abdab234c9615dcbc70e089ab38123122b perly.y
+ * ac323bb6f3cacf4eb8eda6403a58c41f30954d07a4a6d6f7f00de81577b2c79a perly.y
* b6fae5748f9bef6db4740aa5e122b84ac5181852d42474d0ecad621fa4253306 regen_perly.pl
* ex: set ro: */