File tree Expand file tree Collapse file tree 3 files changed +65
-8
lines changed Expand file tree Collapse file tree 3 files changed +65
-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 @@ -423,6 +423,30 @@ EXPECT
423
423
Can't redeclare "state" in "state" at - line 2, near ", state"
424
424
Execution of - aborted due to compilation errors.
425
425
########
426
+ # NAME catch (my $x) errors
427
+ use feature 'try';
428
+ try {} catch (my $x) {}
429
+ EXPECT
430
+ Can't redeclare catch variable as "my" at - line 2, near "(my"
431
+ syntax error at - line 2, near "(my "
432
+ Execution of - aborted due to compilation errors.
433
+ ########
434
+ # NAME catch (our $x) errors
435
+ use feature 'try';
436
+ try {} catch (our $x) {}
437
+ EXPECT
438
+ Can't redeclare catch variable as "our" at - line 2, near "(our"
439
+ syntax error at - line 2, near "(our "
440
+ Execution of - aborted due to compilation errors.
441
+ ########
442
+ # NAME catch (state $x) errors
443
+ use feature 'try', 'state';
444
+ try {} catch (state $x) {}
445
+ EXPECT
446
+ Can't redeclare catch variable as "state" at - line 2, near "(state"
447
+ syntax error at - line 2, near "(state "
448
+ Execution of - aborted due to compilation errors.
449
+ ########
426
450
# NAME BEGIN <> [perl #125341]
427
451
BEGIN <>
428
452
EXPECT
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