In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/f3106bc89eb4bbffee5ca7cb67bd63d2f3ce87bf?hp=9cd8e8a586b62830fc3c73f9acb7411a1639c3ce>

- Log -----------------------------------------------------------------
commit f3106bc89eb4bbffee5ca7cb67bd63d2f3ce87bf
Author: Lukas Mai <[email protected]>
Date:   Mon Aug 17 21:59:41 2015 +0200

    disallow nested declarations [perl #125587] [perl #121058]
-----------------------------------------------------------------------

Summary of changes:
 pod/perldiag.pod |  5 +++++
 t/lib/croak/toke | 45 +++++++++++++++++++++++++++++++++++++++++++++
 t/op/sort.t      |  4 ++--
 toke.c           |  8 ++++++++
 4 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index f47fd3e..2effeeb 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 a061ac8..78ff6cd 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 2e3ba68..05c923f 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');
diff --git a/toke.c b/toke.c
index 16d1252..7a0f1b6 100644
--- a/toke.c
+++ b/toke.c
@@ -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)) {

--
Perl5 Master Repository

Reply via email to