This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t allow name after our/state sub
authorFather Chrysostomos <sprout@cpan.org>
Sun, 1 Jul 2012 00:31:32 +0000 (17:31 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 16 Sep 2012 05:44:52 +0000 (22:44 -0700)
It was a mistake that this was ever allowed.

pod/perldiag.pod
t/lib/croak/toke
toke.c

index 3618d79..6d4eea0 100644 (file)
@@ -2802,7 +2802,7 @@ blank.
 (F) A double-quoted string ended with "\c", without the required control
 character name.
 
-=item Missing name in "my sub"
+=item Missing name in "%s sub"
 
 (F) The reserved syntax for lexically scoped subroutines requires that
 they have a name with which they can be found.
index ddfaaeb..f979ea0 100644 (file)
@@ -14,6 +14,17 @@ my sub;
 EXPECT
 Missing name in "my sub" at - line 1.
 ########
+# NAME Missing name in "our sub"
+our sub;
+EXPECT
+Missing name in "our sub" at - line 1.
+########
+# NAME Missing name in "state sub"
+use 5.01;
+state sub;
+EXPECT
+Missing name in "state sub" at - line 2.
+########
 # NAME Unterminated delimiter for here document
 <<"foo
 EXPECT
diff --git a/toke.c b/toke.c
index d6ac752..6437344 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -8214,6 +8214,7 @@ Perl_yylex(pTHX)
                d = s;
                s = SKIPSPACE2(s,tmpwhite);
 #else
+               d = s;
                s = skipspace(s);
 #endif
 
@@ -8258,8 +8259,13 @@ Perl_yylex(pTHX)
 #endif
                }
                else {
-                   if (key == KEY_my)
-                       Perl_croak(aTHX_ "Missing name in \"my sub\"");
+                   if (key == KEY_my || key == KEY_our || key==KEY_state)
+                   {
+                       *d = '\0';
+                       /* diag_listed_as: Missing name in "%s sub" */
+                       Perl_croak(aTHX_
+                                 "Missing name in \"%s\"", PL_bufptr);
+                   }
                    PL_expect = XTERMBLOCK;
                    attrful = XATTRTERM;
                    sv_setpvs(PL_subname,"?");