From: Rafael Garcia-Suarez Date: Tue, 19 Jul 2005 09:45:24 +0000 (+0000) Subject: Overhaul the semantics of the warning X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f2f96cd564e6a3029bcc2182ffccc4f92f518fb6;p=p5sagit%2Fp5-mst-13.2.git Overhaul the semantics of the warning ""%s" variable %s masks earlier declaration", based on a patch by Rick Delaney. Now we have : my $x; my $x; # warns my $x; our $x; # warns our $x; my $x; # warns our $x; our $x; # silent p4raw-id: //depot/perl@25179 --- diff --git a/pad.c b/pad.c index 2af57ef..7366c9a 100644 --- a/pad.c +++ b/pad.c @@ -515,8 +515,7 @@ Perl_pad_check_dup(pTHX_ const char *name, bool is_our, const HV *ourstash) && sv != &PL_sv_undef && !SvFAKE(sv) && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0) - && (!is_our - || ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)) + && !(is_our && (SvFLAGS(sv) & SVpad_OUR)) && strEQ(name, SvPVX_const(sv))) { Perl_warner(aTHX_ packWARN(WARN_MISC), diff --git a/t/lib/warnings/pad b/t/lib/warnings/pad index f0dce60..f25452f 100644 --- a/t/lib/warnings/pad +++ b/t/lib/warnings/pad @@ -33,51 +33,70 @@ use warnings 'misc' ; my $x ; my $x ; my $y = my $y ; +my $p ; +package X ; +my $p ; +package main ; no warnings 'misc' ; my $x ; my $y ; +my $p ; EXPECT "my" variable $x masks earlier declaration in same scope at - line 4. "my" variable $y masks earlier declaration in same statement at - line 5. +"my" variable $p masks earlier declaration in same scope at - line 8. ######## # pad.c use warnings 'misc' ; our $x ; our $x ; our $y = our $y ; -no warnings 'misc' ; -our $x ; -our $y ; +our $p ; +package X ; +our $p ; EXPECT -"our" variable $x masks earlier declaration in same scope at - line 4. -"our" variable $y masks earlier declaration in same statement at - line 5. ######## # pad.c use warnings 'misc' ; our $x ; my $x ; our $y = my $y ; +our $p ; +package X ; +my $p ; +package main ; no warnings 'misc' ; our $z ; my $z ; our $t = my $t ; +our $q ; +package X ; +my $q ; EXPECT "my" variable $x masks earlier declaration in same scope at - line 4. "my" variable $y masks earlier declaration in same statement at - line 5. +"my" variable $p masks earlier declaration in same scope at - line 8. ######## # pad.c -# TODO not implemented yet use warnings 'misc' ; my $x ; our $x ; my $y = our $y ; +my $p ; +package X ; +our $p ; +package main ; no warnings 'misc' ; my $z ; our $z ; my $t = our $t ; +my $q ; +package X ; +our $q ; EXPECT -"our" variable $x masks earlier declaration in same scope at - line 5. -"our" variable $y masks earlier declaration in same statement at - line 6. +"our" variable $x masks earlier declaration in same scope at - line 4. +"our" variable $y masks earlier declaration in same statement at - line 5. +"our" variable $p masks earlier declaration in same scope at - line 8. ######## # pad.c use warnings 'closure' ; @@ -219,6 +238,13 @@ EXPECT ######## use warnings 'misc' ; +my $x; +{ + my $x; +} +EXPECT +######## +use warnings 'misc' ; our $x; { our $x; @@ -227,6 +253,20 @@ EXPECT "our" variable $x redeclared at - line 4. (Did you mean "local" instead of "our"?) ######## +use warnings 'misc' ; +our $x; +{ + my $x; +} +EXPECT +######## +use warnings 'misc' ; +my $x; +{ + our $x; +} +EXPECT +######## # an our var being introduced should suppress errors about global syms use strict; use warnings;