This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
$object ~~ undef should always test for definedness
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 13 Feb 2009 21:08:06 +0000 (22:08 +0100)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 13 Feb 2009 21:08:06 +0000 (22:08 +0100)
(even if $object hasn't overloaded the ~~ operator)

pp_ctl.c
t/op/smartmatch.t

index f118d57..f512832 100644 (file)
--- 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;
index 86ea187..393bf4c 100644 (file)
@@ -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