From: Rafael Garcia-Suarez Date: Sat, 31 Mar 2007 06:23:12 +0000 (+0000) Subject: Fix the error message "Can't call method "DOES" on unblessed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=59e7186f90f13f9b1945035df4ce5a5117d604dc;p=p5sagit%2Fp5-mst-13.2.git Fix the error message "Can't call method "DOES" on unblessed reference". p4raw-id: //depot/perl@30806 --- diff --git a/pp_hot.c b/pp_hot.c index 83ed613..2f2876b 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -3024,6 +3024,7 @@ S_method_common(pTHX_ SV* meth, U32* hashp) && SvOBJECT(ob)))) { Perl_croak(aTHX_ "Can't call method \"%s\" on unblessed reference", + (SvSCREAM(meth) && strEQ(name,"isa")) ? "DOES" : name); } diff --git a/t/op/universal.t b/t/op/universal.t index 69067e8..9817d3f 100755 --- a/t/op/universal.t +++ b/t/op/universal.t @@ -10,7 +10,7 @@ BEGIN { require "./test.pl"; } -plan tests => 110; +plan tests => 111; $a = {}; bless $a, "Bob"; @@ -222,4 +222,9 @@ package Bodine; Bodine->isa('Pig'); *isa = \&UNIVERSAL::isa; eval { isa({}, 'HASH') }; -::is($@, '', "*isa correctly found") +::is($@, '', "*isa correctly found"); + +package main; +eval { UNIVERSAL::DOES([], "foo") }; +like( $@, qr/Can't call method "DOES" on unblessed reference/, + 'DOES call error message says DOES, not isa' ); diff --git a/universal.c b/universal.c index adfddb5..182b5c9 100644 --- a/universal.c +++ b/universal.c @@ -185,6 +185,7 @@ Perl_sv_does(pTHX_ SV *sv, const char *name) { const char *classname; bool does_it; + SV *methodname; dSP; ENTER; @@ -210,7 +211,12 @@ Perl_sv_does(pTHX_ SV *sv, const char *name) XPUSHs(sv_2mortal(newSVpv(name, 0))); PUTBACK; - call_method("isa", G_SCALAR); + methodname = sv_2mortal(newSVpv("isa", 0)); + /* ugly hack: use the SvSCREAM flag so S_method_common + * can figure out we're calling DOES() and not isa(), + * and report eventual errors correctly. --rgs */ + SvSCREAM_on(methodname); + call_sv(methodname, G_SCALAR | G_METHOD); SPAGAIN; does_it = SvTRUE( TOPs );