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
14851485or define F<PERL_ENV_TABLES> (see L<perlvms>) so that environ is not
14861486searched.
14871487
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+
14881501=item Can't redeclare "%s" in "%s"
14891502
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)>.
14921505
14931506=item Can't "redo" outside a loop block
14941507
Original file line number Diff line number Diff line change @@ -423,6 +423,30 @@ EXPECT
423423Can't redeclare "state" in "state" at - line 2, near ", state"
424424Execution of - aborted due to compilation errors.
425425########
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+ ########
426450# NAME BEGIN <> [perl #125341]
427451BEGIN <>
428452EXPECT
Original file line number Diff line number Diff line change @@ -7190,17 +7190,37 @@ yyl_do(pTHX_ char *s, I32 orig_keyword)
71907190 OPERATOR (KW_DO );
71917191}
71927192
7193+ static const char *
7194+ declarator_name (I32 k ) {
7195+ switch (k ) {
7196+ case KEY_my : return "my" ;
7197+ case KEY_state : return "state" ;
7198+ case KEY_our : return "our" ;
7199+ case KEY_field : return "field" ;
7200+ case KEY_catch : return "catch" ;
7201+ default : return "???" ;
7202+ }
7203+ }
7204+
71937205static int
71947206yyl_my (pTHX_ char * s , I32 my )
71957207{
7208+ assert (my == KEY_my || my == KEY_state || my == KEY_our );
71967209 if (PL_in_my ) {
71977210 PL_bufptr = s ;
7198- yyerror (form (
7199- "Can't redeclare \"%s\" in \"%s\"" ,
7200- my == KEY_my ? "my" :
7201- my == KEY_state ? "state" : "our" ,
7202- PL_in_my == KEY_my ? "my" :
7203- PL_in_my == KEY_state ? "state" : "our" ));
7211+ if (PL_in_my == KEY_catch ) {
7212+ yyerror (form (
7213+ "Can't redeclare catch variable as \"%s\"" ,
7214+ declarator_name (my )
7215+ ));
7216+ } else {
7217+ assert (PL_in_my == KEY_my || PL_in_my == KEY_state || PL_in_my == KEY_our );
7218+ yyerror (form (
7219+ "Can't redeclare \"%s\" in \"%s\"" ,
7220+ declarator_name (my ),
7221+ declarator_name (PL_in_my )
7222+ ));
7223+ }
72047224 }
72057225 PL_in_my = (U16 )my ;
72067226 s = skipspace (s );
You can’t perform that action at this time.
0 commit comments