diff options
author | Lukas Mai <l.mai@web.de> | 2015-08-17 21:59:41 +0200 |
---|---|---|
committer | Lukas Mai <l.mai@web.de> | 2015-08-18 22:34:22 +0200 |
commit | f3106bc89eb4bbffee5ca7cb67bd63d2f3ce87bf (patch) | |
tree | e76f7aee1fd75771d5e78d487e7131761c494f4d | |
parent | 9cd8e8a586b62830fc3c73f9acb7411a1639c3ce (diff) | |
download | perl-f3106bc89eb4bbffee5ca7cb67bd63d2f3ce87bf.tar.gz |
disallow nested declarations [perl #125587] [perl #121058]
-rw-r--r-- | pod/perldiag.pod | 5 | ||||
-rw-r--r-- | t/lib/croak/toke | 45 | ||||
-rw-r--r-- | t/op/sort.t | 4 | ||||
-rw-r--r-- | toke.c | 8 |
4 files changed, 60 insertions, 2 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod index f47fd3efcb..2effeeb875 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1217,6 +1217,11 @@ missing. You need to figure out where your CRTL misplaced its environ or define F<PERL_ENV_TABLES> (see L<perlvms>) so that environ is not searched. +=item Can't redeclare "%s" in "%s" + +(F) A "my", "our" or "state" declaration was found within another declaration, +such as C<my ($x, my($y), $z)> or C<our (my $x)>. + =item Can't "redo" outside a loop block (F) A "redo" statement was executed to restart the current block, but diff --git a/t/lib/croak/toke b/t/lib/croak/toke index a061ac8cf7..78ff6cd855 100644 --- a/t/lib/croak/toke +++ b/t/lib/croak/toke @@ -234,3 +234,48 @@ Constant(q) unknown at - line 12, near ""a"" <<"foo EXPECT Unterminated delimiter for here document at - line 1. +######## +# NAME my (our $x) errors +my (our $x); +EXPECT +Can't redeclare "our" in "my" at - line 1, at end of line +Execution of - aborted due to compilation errors. +######## +# NAME our (my $x) errors +our (my $x); +EXPECT +Can't redeclare "my" in "our" at - line 1, at end of line +Execution of - aborted due to compilation errors. +######## +# NAME state (my $x) errors +use feature 'state'; +state (my $x); +EXPECT +Can't redeclare "my" in "state" at - line 2, at end of line +Execution of - aborted due to compilation errors. +######## +# NAME our (state $x) errors +use feature 'state'; +our (state $x); +EXPECT +Can't redeclare "state" in "our" at - line 2, at end of line +Execution of - aborted due to compilation errors. +######## +# NAME my (my $x) errors +my (my $x, $y, $z); +EXPECT +Can't redeclare "my" in "my" at - line 1, at end of line +Execution of - aborted due to compilation errors. +######## +# NAME our (our $x) errors +our ($x, our($y), $z); +EXPECT +Can't redeclare "our" in "our" at - line 1, near ", " +Execution of - aborted due to compilation errors. +######## +# NAME state (state $x) errors +use feature 'state'; +state ($x, $y, state $z); +EXPECT +Can't redeclare "state" in "state" at - line 2, near ", " +Execution of - aborted due to compilation errors. diff --git a/t/op/sort.t b/t/op/sort.t index 2e3ba68828..05c923fb37 100644 --- a/t/op/sort.t +++ b/t/op/sort.t @@ -859,12 +859,12 @@ is("@b", "1 2 3 3 4 5 7", "comparison result as string"); is($cs, 2, 'overload string called twice'); } -fresh_perl_is('sub w ($$) {my ($l, my $r) = @_; my $v = \@_; undef @_; $l <=> $r}; print join q{ }, sort w 3, 1, 2, 0', +fresh_perl_is('sub w ($$) {my ($l, $r) = @_; my $v = \@_; undef @_; $l <=> $r}; print join q{ }, sort w 3, 1, 2, 0', '0 1 2 3', {stderr => 1, switches => ['-w']}, 'RT #72334'); -fresh_perl_is('sub w ($$) {my ($l, my $r) = @_; my $v = \@_; undef @_; @_ = 0..2; $l <=> $r}; print join q{ }, sort w 3, 1, 2, 0', +fresh_perl_is('sub w ($$) {my ($l, $r) = @_; my $v = \@_; undef @_; @_ = 0..2; $l <=> $r}; print join q{ }, sort w 3, 1, 2, 0', '0 1 2 3', {stderr => 1, switches => ['-w']}, 'RT #72334'); @@ -7605,6 +7605,14 @@ Perl_yylex(pTHX) case KEY_our: case KEY_my: case KEY_state: + if (PL_in_my) { + yyerror(Perl_form(aTHX_ + "Can't redeclare \"%s\" in \"%s\"", + tmp == KEY_my ? "my" : + tmp == KEY_state ? "state" : "our", + PL_in_my == KEY_my ? "my" : + PL_in_my == KEY_state ? "state" : "our")); + } PL_in_my = (U16)tmp; s = skipspace(s); if (isIDFIRST_lazy_if(s,UTF)) { |