/* Since cloneable anon subs can be nested, CvOUTSIDE may point
* to a prototype; we instead want the cloned parent who called us.
- * Note that in general for formats, CvOUTSIDE != find_runcv */
+ * Note that in general for formats, CvOUTSIDE != find_runcv; formats
+ * inside closures, however, only work if CvOUTSIDE == find_runcv.
+ */
outside = CvOUTSIDE(proto);
if (!outside || (CvCLONE(outside) && ! CvCLONED(outside)))
outside = find_runcv(NULL);
+ if (SvTYPE(proto) == SVt_PVFM
+ && CvROOT(outside) != CvROOT(CvOUTSIDE(proto)))
+ outside = CvOUTSIDE(proto);
depth = CvDEPTH(outside);
assert(depth || SvTYPE(proto) == SVt_PVFM);
if (!depth)
if (namesv && namesv != &PL_sv_undef) { /* lexical */
if (SvFAKE(namesv)) { /* lexical from outside? */
sv = outpad[PARENT_PAD_INDEX(namesv)];
- assert(sv);
/* formats may have an inactive parent,
while my $x if $false can leave an active var marked as
stale. And state vars are always available */
- if (SvPADSTALE(sv) && !SvPAD_STATE(namesv)) {
+ if (!sv || (SvPADSTALE(sv) && !SvPAD_STATE(namesv))) {
Perl_ck_warner(aTHX_ packWARN(WARN_CLOSURE),
"Variable \"%"SVf"\" is not available", namesv);
sv = NULL;
#!./perl
-print "1..3\n";
+print "1..5\n";
# Tests bug #22977. Test case from Dave Mitchell.
sub f ($);
undef *bar;
write;
+# A regression introduced in 5.10; format cloning would close over the
+# variables in the currently-running sub (the main CV in this test) if the
+# outer sub were an inactive closure.
+sub baz {
+ my $a;
+ sub {
+ $a;
+ {my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l,$m,$n,$o,$p,$q,$r,$s,$t)}
+ my $x;
+ format STDOUT3 =
+@<<<<<<<<<<<<<<<<<<<<<<<<<
+defined $x ? "not ok 4 - $x" : "ok 4"
+.
+ }
+}
+*STDOUT = *STDOUT3{FORMAT};
+{
+ local $^W = 1;
+ my $w;
+ local $SIG{__WARN__} = sub { $w = shift };
+ write;
+ print "not " unless $w =~ /^Variable "\$x" is not available at/;
+ print "ok 5 - closure var not available when outer sub is inactive\n";
+}