summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2003-07-17 21:33:29 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2003-07-24 08:38:35 +0000
commit929a0744021ffa24a9c2c65030b2f147d2412c41 (patch)
tree1a67a134e89baaf84cdbe1387644e267c37bb562
parent92d1d699fbe61ae998ec027ecaa850aa8a4e9474 (diff)
downloadperl-929a0744021ffa24a9c2c65030b2f147d2412c41.tar.gz
Re: Fatal 5.8.1 error in our $FOO = x if $FOO
Message-ID: <20030717193329.GA2699@fdgroup.com> p4raw-id: //depot/perl@20191
-rw-r--r--pad.c25
-rw-r--r--t/lib/warnings/pad6
2 files changed, 30 insertions, 1 deletions
diff --git a/pad.c b/pad.c
index e8296a3412..dff9a7f947 100644
--- a/pad.c
+++ b/pad.c
@@ -537,9 +537,32 @@ Perl_pad_findmy(pTHX_ char *name)
{
SV *out_sv;
int out_flags;
+ I32 offset;
+ AV *nameav;
+ SV **name_svp;
- return pad_findlex(name, PL_compcv, PL_cop_seqmax, 1,
+ offset = pad_findlex(name, PL_compcv, PL_cop_seqmax, 1,
Null(SV**), &out_sv, &out_flags);
+ if (offset != NOT_IN_PAD)
+ return offset;
+
+ /* look for an our that's being introduced; this allows
+ * our $foo = 0 unless defined $foo;
+ * to not give a warning. (Yes, this is a hack) */
+
+ nameav = (AV*)AvARRAY(CvPADLIST(PL_compcv))[0];
+ name_svp = AvARRAY(nameav);
+ for (offset = AvFILLp(nameav); offset > 0; offset--) {
+ SV *namesv = name_svp[offset];
+ if (namesv && namesv != &PL_sv_undef
+ && !SvFAKE(namesv)
+ && (SvFLAGS(namesv) & SVpad_OUR)
+ && strEQ(SvPVX(namesv), name)
+ && (U32)I_32(SvNVX(namesv)) == PAD_MAX /* min */
+ )
+ return offset;
+ }
+ return NOT_IN_PAD;
}
diff --git a/t/lib/warnings/pad b/t/lib/warnings/pad
index 71f683ed54..65f92c3c70 100644
--- a/t/lib/warnings/pad
+++ b/t/lib/warnings/pad
@@ -168,3 +168,9 @@ our $x;
EXPECT
"our" variable $x redeclared at - line 4.
(Did you mean "local" instead of "our"?)
+########
+# an our var being introduced should suppress errors about global syms
+use strict;
+use warnings;
+our $x unless $x;
+EXPECT