summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pod/perlsyn.pod1
-rw-r--r--pp_ctl.c4
-rw-r--r--t/op/smartmatch.t14
-rw-r--r--t/op/switch.t16
4 files changed, 24 insertions, 11 deletions
diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod
index 2ba30d84c4..92125735a8 100644
--- a/pod/perlsyn.pod
+++ b/pod/perlsyn.pod
@@ -720,6 +720,7 @@ and "Array" entries apply in those cases. (For blessed references, the
Object Any invokes ~~ overloading on $object, or falls back:
Any Num numeric equality $a == $b
Num numish[4] numeric equality $a == $b
+ undef Any undefined !defined($b)
Any Any string equality $a eq $b
1 - empty hashes or arrays will match.
diff --git a/pp_ctl.c b/pp_ctl.c
index 6bb5b40e5e..59ac8c12a8 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4393,6 +4393,10 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
SP -= 2;
goto sm_any_scalar;
}
+ else if (!SvOK(d)) {
+ /* undef ~~ scalar ; we already know that the scalar is SvOK */
+ RETPUSHNO;
+ }
else
sm_any_scalar:
if (SvNIOK(e) || (SvPOK(e) && looks_like_number(e) && SvNIOK(d))) {
diff --git a/t/op/smartmatch.t b/t/op/smartmatch.t
index 58466af7a7..cb0e656b09 100644
--- a/t/op/smartmatch.t
+++ b/t/op/smartmatch.t
@@ -70,7 +70,7 @@ my %keyandmore = map { $_ => 0 } @keyandmore;
my %fooormore = map { $_ => 0 } @fooormore;
# Load and run the tests
-plan tests => 314;
+plan tests => 322;
while (<DATA>) {
next if /^#/ || !/\S/;
@@ -371,7 +371,7 @@ __DATA__
["foo", "bar"] [["foo"], ["bar"]]
! ["foo", "bar"] [qr/o/, "foo"]
["foo", undef, "bar"] [qr/o/, undef, "bar"]
- ["foo", undef, "bar"] [qr/o/, "", "bar"]
+! ["foo", undef, "bar"] [qr/o/, "", "bar"]
! ["foo", "", "bar"] [qr/o/, undef, "bar"]
$deep1 $deep1
@$deep1 @$deep1
@@ -409,6 +409,11 @@ __DATA__
! undef [1, 2, [undef], 4]
! undef @fooormore
undef @sparse
+ undef [undef]
+! 0 [undef]
+! "" [undef]
+! undef [0]
+! undef [""]
# - nested arrays and ~~ distributivity
11 [[11]]
@@ -422,7 +427,8 @@ __DATA__
! 2 3
0 FALSE
3-2 TRUE
- undef 0
+! undef 0
+! (my $u) 0
# Number against string
= 2 "2"
@@ -430,6 +436,8 @@ __DATA__
! 2 "2bananas"
!= 2_3 "2_3" NOWARNINGS
FALSE "0"
+! undef "0"
+! undef ""
# Regex against string
"x" qr/x/
diff --git a/t/op/switch.t b/t/op/switch.t
index d8cb781e10..2012c6c148 100644
--- a/t/op/switch.t
+++ b/t/op/switch.t
@@ -133,15 +133,15 @@ sub check_outside1 { is($_, "outside", "\$_ lexically scoped") }
}
{
no warnings "uninitialized";
- my $ok = 0;
- given (undef) { when(0) {$ok = 1} }
+ my $ok = 1;
+ given (undef) { when(0) {$ok = 0} }
is($ok, 1, "Given(undef) when(0)");
}
{
no warnings "uninitialized";
my $undef;
- my $ok = 0;
- given ($undef) { when(0) {$ok = 1} }
+ my $ok = 1;
+ given ($undef) { when(0) {$ok = 0} }
is($ok, 1, 'Given($undef) when(0)');
}
########
@@ -158,15 +158,15 @@ sub check_outside1 { is($_, "outside", "\$_ lexically scoped") }
}
{
no warnings "uninitialized";
- my $ok = 0;
- given (undef) { when("") {$ok = 1} }
+ my $ok = 1;
+ given (undef) { when("") {$ok = 0} }
is($ok, 1, 'Given(undef) when("")');
}
{
no warnings "uninitialized";
my $undef;
- my $ok = 0;
- given ($undef) { when("") {$ok = 1} }
+ my $ok = 1;
+ given ($undef) { when("") {$ok = 0} }
is($ok, 1, 'Given($undef) when("")');
}
########