This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t say ‘variable &foo’ in warnings
authorFather Chrysostomos <sprout@cpan.org>
Sun, 8 Jul 2012 21:42:39 +0000 (14:42 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 16 Sep 2012 05:45:01 +0000 (22:45 -0700)
It should be ‘subroutine &foo’.  (It could be ‘subroutine foo’, but we
use both forms elsewhere, and &foo is the easier to implement, the &
already being contained in the pad name.)

pad.c
pod/perldiag.pod
t/cmd/lexsub.t

diff --git a/pad.c b/pad.c
index c80a6e7..3bd44b2 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -875,9 +875,11 @@ S_pad_check_dup(pTHX_ SV *name, U32 flags, const HV *ourstash)
        {
            if (is_our && (SvPAD_OUR(sv)))
                break; /* "our" masking "our" */
+           /* diag_listed_as: "%s" variable %s masks earlier declaration in same %s */
            Perl_warner(aTHX_ packWARN(WARN_MISC),
-               "\"%s\" variable %"SVf" masks earlier declaration in same %s",
+               "\"%s\" %s %"SVf" masks earlier declaration in same %s",
                (is_our ? "our" : PL_parser->in_my == KEY_my ? "my" : "state"),
+               *SvPVX(sv) == '&' ? "subroutine" : "variable",
                sv,
                (COP_SEQ_RANGE_HIGH(sv) == PERL_PADSEQ_INTRO
                    ? "scope" : "statement"));
index 6d4eea0..a874946 100644 (file)
@@ -4561,6 +4561,14 @@ was either never opened or has since been closed.
 stubs.  Stubs should never be implicitly created, but explicit calls to
 C<can> may break this.
 
+=item "%s" subroutine &%s masks earlier declaration in same %s
+
+(W misc) A "my" or "state" subroutine has been redeclared in the
+current scope or statement, effectively eliminating all access to
+the previous instance.  This is almost always a typographical error.
+Note that the earlier subroutine will still exist until the end of
+the scope or until all closure referents to it are destroyed.
+
 =item Subroutine %s redefined
 
 (W redefine) You redefined a subroutine.  To suppress this warning, say
index 36689e7..d940d1c 100644 (file)
@@ -191,12 +191,10 @@ package main;
     state sub foo;
     state sub foo {};
   ';
-on;
   is $w,
-     '"state" subroutine foo masks earlier declaration in same scope at '
+     '"state" subroutine &foo masks earlier declaration in same scope at '
    . "squidges line 88.\n",
-     'redefinition warning for state sub';
-off;
+     'warning for state sub masking earlier declaration';
 }
 # Since state vars inside anonymous subs are cloned at the same time as the
 # anonymous subs containing them, the same should happen for state subs.