From 33570f8ba08e966c4572bcd9146cb9580efcac82 Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Suarez Date: Fri, 13 Feb 2009 22:08:06 +0100 Subject: [PATCH] $object ~~ undef should always test for definedness (even if $object hasn't overloaded the ~~ operator) --- pp_ctl.c | 8 ++++++-- t/op/smartmatch.t | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) 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 -- 1.8.3.1