File tree Expand file tree Collapse file tree 2 files changed +41
-8
lines changed Expand file tree Collapse file tree 2 files changed +41
-8
lines changed Original file line number Diff line number Diff line change @@ -1485,10 +1485,23 @@ missing. You need to figure out where your CRTL misplaced its environ
1485
1485
or define F<PERL_ENV_TABLES> (see L<perlvms>) so that environ is not
1486
1486
searched.
1487
1487
1488
+ =item Can't redeclare catch variable as "%s"
1489
+
1490
+ (F) A C<my>, C<our> or C<state> keyword was used with the exception variable in
1491
+ a C<catch> block:
1492
+
1493
+ try { ... }
1494
+ catch (my $e) { ... }
1495
+ # or catch (our $e) { ... }
1496
+ # or catch (state $e) { ... }
1497
+
1498
+ This is not valid syntax. C<catch> takes a bare variable name, which is
1499
+ automatically lexically declared.
1500
+
1488
1501
=item Can't redeclare "%s" in "%s"
1489
1502
1490
- (F) A "my", " our" or " state" declaration was found within another declaration,
1491
- such as C<my ($x, my($y), $z)> or C<our (my $x)>.
1503
+ (F) A C<my>, C< our> or C< state> declaration was found within another
1504
+ declaration, such as C<my ($x, my($y), $z)> or C<our (my $x)>.
1492
1505
1493
1506
=item Can't "redo" outside a loop block
1494
1507
Original file line number Diff line number Diff line change @@ -7186,17 +7186,37 @@ yyl_do(pTHX_ char *s, I32 orig_keyword)
7186
7186
OPERATOR (KW_DO );
7187
7187
}
7188
7188
7189
+ static const char *
7190
+ declarator_name (I32 k ) {
7191
+ switch (k ) {
7192
+ case KEY_my : return "my" ;
7193
+ case KEY_state : return "state" ;
7194
+ case KEY_our : return "our" ;
7195
+ case KEY_field : return "field" ;
7196
+ case KEY_catch : return "catch" ;
7197
+ default : return "???" ;
7198
+ }
7199
+ }
7200
+
7189
7201
static int
7190
7202
yyl_my (pTHX_ char * s , I32 my )
7191
7203
{
7204
+ assert (my == KEY_my || my == KEY_state || my == KEY_our );
7192
7205
if (PL_in_my ) {
7193
7206
PL_bufptr = s ;
7194
- yyerror (form (
7195
- "Can't redeclare \"%s\" in \"%s\"" ,
7196
- my == KEY_my ? "my" :
7197
- my == KEY_state ? "state" : "our" ,
7198
- PL_in_my == KEY_my ? "my" :
7199
- PL_in_my == KEY_state ? "state" : "our" ));
7207
+ if (PL_in_my == KEY_catch ) {
7208
+ yyerror (form (
7209
+ "Can't redeclare catch variable as \"%s\"" ,
7210
+ declarator_name (my )
7211
+ ));
7212
+ } else {
7213
+ assert (PL_in_my == KEY_my || PL_in_my == KEY_state || PL_in_my == KEY_our );
7214
+ yyerror (form (
7215
+ "Can't redeclare \"%s\" in \"%s\"" ,
7216
+ declarator_name (my ),
7217
+ declarator_name (PL_in_my )
7218
+ ));
7219
+ }
7200
7220
}
7201
7221
PL_in_my = (U16 )my ;
7202
7222
s = skipspace (s );
You can’t perform that action at this time.
0 commit comments