From: Rafael Garcia-Suarez Date: Tue, 19 Jul 2005 14:12:38 +0000 (+0000) Subject: Extend the the "our variable redeclared" warning to the case: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f73a9f140198d1b3d1c2f2b62d4fd14dc5667c3;p=p5sagit%2Fp5-mst-13.2.git Extend the the "our variable redeclared" warning to the case: our $x; our $x; and add more tests p4raw-id: //depot/perl@25187 --- diff --git a/pad.c b/pad.c index 7366c9a..58a37e6 100644 --- a/pad.c +++ b/pad.c @@ -515,9 +515,10 @@ 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)) && strEQ(name, SvPVX_const(sv))) { + if (is_our && (SvFLAGS(sv) & SVpad_OUR)) + break; /* "our" masking "our" */ Perl_warner(aTHX_ packWARN(WARN_MISC), "\"%s\" variable %s masks earlier declaration in same %s", (is_our ? "our" : "my"), @@ -540,8 +541,9 @@ Perl_pad_check_dup(pTHX_ const char *name, bool is_our, const HV *ourstash) { Perl_warner(aTHX_ packWARN(WARN_MISC), "\"our\" variable %s redeclared", name); - Perl_warner(aTHX_ packWARN(WARN_MISC), - "\t(Did you mean \"local\" instead of \"our\"?)\n"); + if (off <= PL_comppad_name_floor) + Perl_warner(aTHX_ packWARN(WARN_MISC), + "\t(Did you mean \"local\" instead of \"our\"?)\n"); break; } } while ( off-- > 0 ); diff --git a/t/lib/strict/vars b/t/lib/strict/vars index 06d9e00..16deab9 100644 --- a/t/lib/strict/vars +++ b/t/lib/strict/vars @@ -372,14 +372,14 @@ EXPECT 20 ######## -# multiple our declarations in same scope, same package, no warning +# multiple our declarations in same scope, same package, warning use strict 'vars'; use warnings; our $foo; ${foo} = 10; our $foo; EXPECT - +"our" variable $foo redeclared at - line 7. ######## # multiple our declarations in same scope, same package, warning @@ -390,12 +390,14 @@ use warnings; our $foo; { our $foo; + our $foo; package Foo; our $foo; } EXPECT "our" variable $foo redeclared at - line 9. (Did you mean "local" instead of "our"?) +"our" variable $foo redeclared at - line 10. ######## --FILE-- abc diff --git a/t/lib/warnings/pad b/t/lib/warnings/pad index f25452f..bf5c367 100644 --- a/t/lib/warnings/pad +++ b/t/lib/warnings/pad @@ -1,6 +1,6 @@ pad.c AOK - "my" variable %s masks earlier declaration in same scope + "%s" variable %s masks earlier declaration in same scope my $x; my $x ; @@ -49,16 +49,6 @@ EXPECT # pad.c use warnings 'misc' ; our $x ; -our $x ; -our $y = our $y ; -our $p ; -package X ; -our $p ; -EXPECT -######## -# pad.c -use warnings 'misc' ; -our $x ; my $x ; our $y = my $y ; our $p ; @@ -244,20 +234,53 @@ my $x; } EXPECT ######## +# pad.c +use warnings 'misc' ; +our $x ; +our $x ; +our $y = our $y ; +our $p ; +package X ; +our $p ; +package main ; +no warnings 'misc' ; +our $a ; +our $a ; +our $b = our $b ; +our $c ; +package X ; +our $c ; +EXPECT +"our" variable $x redeclared at - line 4. +"our" variable $y redeclared at - line 5. +######## use warnings 'misc' ; our $x; { our $x; } +our $x; +no warnings 'misc' ; +our $y; +{ + our $y; +} +our $y; EXPECT "our" variable $x redeclared at - line 4. (Did you mean "local" instead of "our"?) +"our" variable $x redeclared at - line 6. ######## use warnings 'misc' ; our $x; { my $x; } +no warnings 'misc' ; +our $y; +{ + my $y; +} EXPECT ######## use warnings 'misc' ; @@ -265,6 +288,23 @@ my $x; { our $x; } +no warnings 'misc' ; +my $y; +{ + our $y; +} +EXPECT +######## +use warnings 'misc' ; +my $x; +{ + my $x; +} +no warnings 'misc' ; +my $y; +{ + my $y; +} EXPECT ######## # an our var being introduced should suppress errors about global syms