Fix recursion warning for ‘no warnings; goto &sub’
authorFather Chrysostomos <sprout@cpan.org>
Sat, 17 Sep 2011 07:27:14 +0000 (00:27 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 17 Sep 2011 07:27:14 +0000 (00:27 -0700)
Commit 309aab3a made goto &foo make the lexical hints of the caller of
the sub containing the goto visible when foo is called.  CORE subs
need this to function properly when ‘goneto’.  But in that commit I
put the PL_curcop assignment before the recursion check, causing the
warning settings of the caller to be used, instead of those at the
goto.  This commit moves the PL_curcop further down in pp_goto.

pp_ctl.c
t/op/goto.t

index 603d0a5..2e89b70 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2908,7 +2908,6 @@ PP(pp_goto)
                }
                cx->blk_sub.cv = cv;
                cx->blk_sub.olddepth = CvDEPTH(cv);
-               PL_curcop = cx->blk_oldcop;
 
                CvDEPTH(cv)++;
                if (CvDEPTH(cv) < 2)
@@ -2918,6 +2917,7 @@ PP(pp_goto)
                        sub_crush_depth(cv);
                    pad_push(padlist, CvDEPTH(cv));
                }
+               PL_curcop = cx->blk_oldcop;
                SAVECOMPPAD();
                PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));
                if (CxHASARGS(cx))
index 5fa3116..f2f9162 100644 (file)
@@ -10,7 +10,7 @@ BEGIN {
 
 use warnings;
 use strict;
-plan tests => 77;
+plan tests => 78;
 our $TODO;
 
 my $deprecated = 0;
@@ -415,7 +415,11 @@ sub recurse2 {
     my $x = shift;
     $_[0] ? +1 + recurse1($_[0] - 1) : 0
 }
+my $w = 0;
+$SIG{__WARN__} = sub { ++$w };
 is(recurse1(500), 500, 'recursive goto &foo');
+is $w, 0, 'no recursion warnings for "no warnings; goto &sub"';
+delete $SIG{__WARN__};
 
 # [perl #32039] Chained goto &sub drops data too early.