This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct ‘"my" variable "&f::b"...’ message
authorFather Chrysostomos <sprout@cpan.org>
Mon, 6 Oct 2014 00:25:57 +0000 (17:25 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 6 Oct 2014 00:25:57 +0000 (17:25 -0700)
"my" variable &foo::bar can't be in a package at - line 2, near "my sub foo::bar"

It should say ‘subroutine’, not ‘variable’.  When I implemented lexi-
cal subs, I thought I caught all these, must I missed this one.

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

diff --git a/perl.h b/perl.h
index b958d74..e6e1320 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -4600,7 +4600,7 @@ EXTCONST char PL_no_dir_func[]
 EXTCONST char PL_no_func[]
   INIT("The %s function is unimplemented");
 EXTCONST char PL_no_myglob[]
-  INIT("\"%s\" variable %s can't be in a package");
+  INIT("\"%s\" %se %s can't be in a package");
 EXTCONST char PL_no_localize_ref[]
   INIT("Can't localize through a reference");
 EXTCONST char PL_memory_wrap[]
index b4559ce..cfb8a07 100644 (file)
@@ -3280,6 +3280,11 @@ See L<perlfunc/pack>.
 (F) Lexically scoped subroutines are not yet implemented.  Don't try
 that yet.
 
+=item "my" subroutine %s can't be in a package
+
+(F) Lexically scoped subroutines aren't in a package, so it doesn't make
+sense to try to declare one with a package qualifier on the front.
+
 =item "my %s" used in sort comparison
 
 (W syntax) The package variables $a and $b are used for sort comparisons.
@@ -5211,6 +5216,11 @@ unless there was a failure.  You probably wanted to use system()
 instead, which does return.  To suppress this warning, put the exec() in
 a block by itself.
 
+=item "state" subroutine %s can't be in a package
+
+(F) Lexically scoped subroutines aren't in a package, so it doesn't make
+sense to try to declare one with a package qualifier on the front.
+
 =item "state %s" used in sort comparison
 
 (W syntax) The package variables $a and $b are used for sort comparisons.
index c6444da..9c8dd54 100644 (file)
@@ -49,6 +49,17 @@ EXPECT
 The lexical_subs feature is experimental at - line 2.
 Missing name in "state sub" at - line 2.
 ########
+# NAME my sub pack::foo
+use feature 'lexical_subs', 'state';
+my sub foo::bar;
+state sub foo::bear;
+EXPECT
+The lexical_subs feature is experimental at - line 2.
+The lexical_subs feature is experimental at - line 3.
+"my" subroutine &foo::bar can't be in a package at - line 2, near "my sub foo::bar"
+"state" subroutine &foo::bear can't be in a package at - line 3, near "state sub foo::bear"
+Execution of - aborted due to compilation errors.
+########
 # NAME Integer constant overloading returning undef
 use overload;
 BEGIN { overload::constant integer => sub {}; undef *^H }
diff --git a/toke.c b/toke.c
index f48fa28..9efdd80 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -8118,7 +8118,9 @@ S_pending_ident(pTHX)
                 /* PL_no_myglob is constant */
                 GCC_DIAG_IGNORE(-Wformat-nonliteral);
                 yyerror_pv(Perl_form(aTHX_ PL_no_myglob,
-                           PL_in_my == KEY_my ? "my" : "state", PL_tokenbuf),
+                            PL_in_my == KEY_my ? "my" : "state",
+                            *PL_tokenbuf == '&' ? "subroutin" : "variabl",
+                            PL_tokenbuf),
                             UTF ? SVf_UTF8 : 0);
                 GCC_DIAG_RESTORE;
             }