From: Rafael Garcia-Suarez Date: Mon, 7 Dec 2009 12:41:05 +0000 (+0100) Subject: Fix [perl #71078] Smart match against @_ gives false negatives X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=69c3dccf5322a59cb855347c04712ba11b65328f;p=p5sagit%2Fp5-mst-13.2.git Fix [perl #71078] Smart match against @_ gives false negatives @_ can contain NULLs for undefined elements --- diff --git a/pp_ctl.c b/pp_ctl.c index e69107e..68a42d7 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -4321,7 +4321,8 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other) SV * const * const other_elem = av_fetch(other_av, i, FALSE); if (!this_elem || !other_elem) { - if (this_elem || other_elem) + if ((this_elem && SvOK(*this_elem)) + || (other_elem && SvOK(*other_elem))) RETPUSHNO; } else if (hv_exists_ent(seen_this, diff --git a/t/op/switch.t b/t/op/switch.t index 80d6b98..92facef 100644 --- a/t/op/switch.t +++ b/t/op/switch.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings; -plan tests => 128; +plan tests => 132; # The behaviour of the feature pragma should be tested by lib/switch.t # using the tests in t/lib/switch/*. This file tests the behaviour of @@ -1024,6 +1024,13 @@ GIVEN5: is($flag, 1, "goto inside given and when to the given stmt"); } +# test with unreified @_ in smart match [perl #71078] +sub unreified_check { ok([@_] ~~ \@_) } # should always match +unreified_check(1,2,"lala"); +unreified_check(1,2,undef); +unreified_check(undef); +unreified_check(undef,""); + # Okay, that'll do for now. The intricacies of the smartmatch # semantics are tested in t/op/smartmatch.t __END__