Don’t croak for local *DetachedStash::method
authorFather Chrysostomos <sprout@cpan.org>
Wed, 28 Nov 2012 20:39:04 +0000 (12:39 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 29 Nov 2012 17:11:30 +0000 (09:11 -0800)
save_gp was trying to call mro_method_changed_in even if the stash had
been detached.

This is a regression from 5.12.

scope.c
t/mro/basic.t

diff --git a/scope.c b/scope.c
index 8eca725..c4a2222 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -285,8 +285,9 @@ Perl_save_gp(pTHX_ GV *gv, I32 empty)
 
     if (empty) {
        GP *gp = Perl_newGP(aTHX_ gv);
+       HV * const stash = GvSTASH(gv);
 
-       if (GvCVu(gv))
+       if (GvCVu(gv) && stash && HvENAME(stash))
             mro_method_changed_in(GvSTASH(gv)); /* taking a method out of circulation ("local")*/
        if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) {
            gp->gp_io = newIO();
index 10aa44c..cc1386c 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-BEGIN { require q(./test.pl); } plan(tests => 54);
+BEGIN { require q(./test.pl); } plan(tests => 55);
 
 require mro;
 
@@ -346,3 +346,10 @@ is(eval { MRO_N->testfunc() }, 123);
     @{*fednu::ISA} = "pyfg";
     ok +fednu->isa("pyfg"), 'autovivifying @ISA via *{@ISA}';
 }
+
+{
+    sub Detached::method;
+    my $h = delete $::{"Detached::"};
+    eval { local *Detached::method };
+    is $@, "", 'localising gv-with-cv belonging to detached package';
+}