diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-01-25 20:22:01 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-01-25 20:22:01 +0000 |
commit | 336337397a650655cf01ecfa4aab8aa7e70c42f4 (patch) | |
tree | 8adcada4f182bb8e26ad7b84779e4cbbfb3d3a95 /op.c | |
parent | d08ede9a86fc6f23c9d8f6a6b0ba2b5edd36ad0f (diff) | |
download | perl-336337397a650655cf01ecfa4aab8aa7e70c42f4.tar.gz |
produce redeclaration warning on C<our $foo; { our $foo; ... }>
p4raw-id: //depot/perl@4891
Diffstat (limited to 'op.c')
-rw-r--r-- | op.c | 33 |
1 files changed, 25 insertions, 8 deletions
@@ -153,22 +153,39 @@ Perl_pad_allocmy(pTHX_ char *name) } if (ckWARN(WARN_UNSAFE) && AvFILLp(PL_comppad_name) >= 0) { SV **svp = AvARRAY(PL_comppad_name); - for (off = AvFILLp(PL_comppad_name); off > PL_comppad_name_floor; off--) { + HV *ourstash = (PL_curstash ? PL_curstash : PL_defstash); + PADOFFSET top = AvFILLp(PL_comppad_name); + for (off = top; off > PL_comppad_name_floor; off--) { if ((sv = svp[off]) && sv != &PL_sv_undef && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0) + && (PL_in_my != KEY_our + || ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)) && strEQ(name, SvPVX(sv))) { - if (PL_in_my != KEY_our - || GvSTASH(sv) == (PL_curstash ? PL_curstash : PL_defstash)) + Perl_warner(aTHX_ WARN_UNSAFE, + "\"%s\" variable %s masks earlier declaration in same %s", + (PL_in_my == KEY_our ? "our" : "my"), + name, + (SvIVX(sv) == PAD_MAX ? "scope" : "statement")); + --off; + break; + } + } + if (PL_in_my == KEY_our) { + while (off >= 0 && off <= top) { + if ((sv = svp[off]) + && sv != &PL_sv_undef + && ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash) + && strEQ(name, SvPVX(sv))) { Perl_warner(aTHX_ WARN_UNSAFE, - "\"%s\" variable %s masks earlier declaration in same %s", - (PL_in_my == KEY_our ? "our" : "my"), - name, - (SvIVX(sv) == PAD_MAX ? "scope" : "statement")); + "\"our\" variable %s redeclared", name); + Perl_warner(aTHX_ WARN_UNSAFE, + "(Did you mean \"local\" instead of \"our\"?)\n"); + break; } - break; + --off; } } } |