This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
isa should fall back to checking @UNIVERSAL::ISA in all cases
authorJesse Luehrs <doy@tozt.net>
Thu, 17 Oct 2013 20:24:58 +0000 (16:24 -0400)
committerJesse Luehrs <doy@tozt.net>
Thu, 17 Oct 2013 20:58:34 +0000 (16:58 -0400)
t/op/universal.t
universal.c

index 7b5cdb0..50d1782 100644 (file)
@@ -10,7 +10,7 @@ BEGIN {
     require "./test.pl";
 }
 
-plan tests => 142;
+plan tests => 144;
 
 $a = {};
 bless $a, "Bob";
@@ -343,3 +343,10 @@ ok(Undeclared->can("foo"));
 ok(!Undeclared->can("something_else"));
 
 ok(Undeclared->isa("UNIVERSAL"));
+
+# keep this at the end to avoid messing up earlier tests, since it modifies
+# @UNIVERSAL::ISA
+@UNIVERSAL::ISA = ('UniversalParent');
+{ package UniversalIsaTest1; }
+ok(UniversalIsaTest1->isa('UniversalParent'));
+ok(UniversalIsaTest2->isa('UniversalParent'));
index 8337e2b..305713f 100644 (file)
@@ -160,15 +160,19 @@ Perl_sv_derived_from_pvn(pTHX_ SV *sv, const char *const name, const STRLEN len,
         type = sv_reftype(sv,0);
        if (type && strEQ(type,name))
            return TRUE;
-       stash = SvOBJECT(sv) ? SvSTASH(sv) : NULL;
+        if (!SvOBJECT(sv))
+            return FALSE;
+       stash = SvSTASH(sv);
     }
     else {
         stash = gv_stashsv(sv, 0);
-        if (!stash)
-            stash = gv_stashpvs("UNIVERSAL", 0);
     }
 
-    return stash ? isa_lookup(stash, name, len, flags) : FALSE;
+    if (stash && isa_lookup(stash, name, len, flags))
+        return TRUE;
+
+    stash = gv_stashpvs("UNIVERSAL", 0);
+    return stash && isa_lookup(stash, name, len, flags);
 }
 
 /*