This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
duplicate signature vars gave wrong warning
authorDavid Mitchell <davem@iabyn.com>
Mon, 1 Aug 2016 10:41:42 +0000 (11:41 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Aug 2016 19:54:42 +0000 (20:54 +0100)
RT #128719. This:

    sub f ($x, $x) {}

gave

    "state" variable $x masks earlier declaration in same scope

This commit changes that to '"my" variable'

t/op/signatures.t
toke.c

index 27b7ead..2782e7e 100644 (file)
@@ -1457,6 +1457,15 @@ is scalar(t145()), undef;
 
 }
 
+{
+    my $w;
+    use warnings qw(misc);
+    local $SIG{__WARN__} = sub { $w .= "@_" };
+    is eval q{sub ($x,$x) { $x}->(1,2)}, 2, "duplicate sig var names";
+    like $w, qr/^"my" variable \$x masks earlier declaration in same scope/,
+            "masking warning";
+}
+
 
 
 use File::Spec::Functions;
diff --git a/toke.c b/toke.c
index 876a29c..8564efc 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -8606,11 +8606,15 @@ S_pending_ident(pTHX_ bool is_sig)
                 o->op_private |= (  PL_tokenbuf[0] == '$' ? OPpARGELEM_SV
                                   : PL_tokenbuf[0] == '@' ? OPpARGELEM_AV
                                   :                         OPpARGELEM_HV);
+                /* make allocmy() warnings be for 'my', not 'state' */
+                PL_in_my = KEY_my;
             }
             else
                 o = newOP(OP_PADANY, 0);
             o->op_targ = allocmy(PL_tokenbuf, tokenbuf_len,
                                                         UTF ? SVf_UTF8 : 0);
+            if (is_sig)
+                PL_in_my = 0;
             pl_yylval.opval = o;
            return PRIVATEREF;
         }