From: Rafael Garcia-Suarez Date: Fri, 13 Feb 2009 21:08:06 +0000 (+0100) Subject: $object ~~ undef should always test for definedness X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=33570f8ba08e966c4572bcd9146cb9580efcac82;p=p5sagit%2Fp5-mst-13.2.git $object ~~ undef should always test for definedness (even if $object hasn't overloaded the ~~ operator) --- diff --git a/pp_ctl.c b/pp_ctl.c index f118d57..f512832 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -4087,8 +4087,12 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other) if (SvGMAGICAL(e)) e = sv_mortalcopy(e); - if (SM_OBJECT) - Perl_croak(aTHX_ "Smart matching a non-overloaded object breaks encapsulation"); + if (SM_OBJECT) { + if (!SvOK(d) || !SvOK(e)) + RETPUSHNO; + else + Perl_croak(aTHX_ "Smart matching a non-overloaded object breaks encapsulation"); + } if (SM_CV_NEP) { I32 c; diff --git a/t/op/smartmatch.t b/t/op/smartmatch.t index 86ea187..393bf4c 100644 --- a/t/op/smartmatch.t +++ b/t/op/smartmatch.t @@ -102,6 +102,7 @@ __DATA__ ! $ov_obj "foo" ! $ov_obj \&foo @ $ov_obj \&fatal +! $ov_obj undef # regular object @ $obj "key" @@ -112,6 +113,7 @@ __DATA__ @ $obj sub { 0 } @ $obj \&foo @ $obj \&fatal +! $obj undef # CODE ref against argument # - arg is code ref