New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when( @n && %n ) fails to smart match #9221
Comments
From @briandfoyCreated by @briandfoyI first mentioned this on p5p in " Clarifying smart match behaviour in With && in a when() and when both arguments are arrays and hashes, the Here's a patch to t/op/switch.t that tests the problem in three Inline Patch--- t/op/switch.t 2008-02-04 21:04:17.000000000 -0600
+++ t/op/switch-new.t 2008-02-04 21:13:27.000000000 -0600
@@ -8,7 +8,7 @@
use strict;
use warnings;
-use Test::More tests => 108;
+use Test::More tests => 111;
# 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
@@ -520,6 +520,66 @@
ok($ok, '((1 == $ok) || "foo") smartmatched');
}
+{ # this should smart match on each side of &&
+ my @n = qw(fred barney betty);
+ my @m = @n;
+
+ my $ok = 0;
+ given( "fred" ) {
+ when( @n ) {
+ $ok++; continue;
+ }
+ when( @m ) {
+ $ok++; continue;
+ }
+ when( @m && @n ) {
+ $ok++;
+ }
+ }
+
+ is($ok, 3, '(@n && @m) smart-matched');
+}
+
+{ # this should smart match on each side of &&
+ my @n = qw(fred barney betty);
+ my %n = map { $_, 1 } @n;
+
+ my $ok = 0;
+ given( "fred" ) {
+ when( @n ) {
+ $ok++; continue;
+ }
+ when( %n ) {
+ $ok++; continue;
+ }
+ when( @n && %n ) {
+ $ok++;
+ }
+ }
+
+ is($ok, 3, '(@n && %n) smart-matched');
+}
+
+{ # this should smart match on each side of &&
+ my %n = map { $_, 1 } qw(fred barney betty);
+ my %m = %n;
+
+ my $ok = 0;
+ given( "fred" ) {
+ when( %m ) {
+ $ok++; continue;
+ }
+ when( %n ) {
+ $ok++; continue;
+ }
+ when( %m && %n ) {
+ $ok++;
+ }
+ }
+
+ is($ok, 3, '(%m && %n) smart-matched');
+}
+
# Make sure we aren't invoking the get-magic more than once
{ # A helper class to count the number of accesses.
@@ -689,7 +749,7 @@
q{Can't "break" in a loop topicalizer});
}
when (1) {
- is($first, 1, "Lecical loop: first");
+ is($first, 1, "Lexical loop: first");
$first = 0;
# Implicit break is okay
} Perl Info
|
From spamdummy3@yahoo.comThis is a bug report for perl from spamdummy3@yahoo.com, "perlsyn" says that in the "when" clause of a "given" block, "or" sub test test('a'); ought, I think, to print six "Y"s, but instead it prints: Y I asked about this weirdness on Perl Monks Flags: This perlbug was built using Perl 5.10.0 - Sat Jun 7 17:43:34 EDT 2008 Site configuration information for perl 5.10.0: Configured by hippo at Sat Jun 7 13:10:17 EDT 2008. Summary of my perl5 (revision 5 version 10 subversion 0) configuration: Locally applied patches: @INC for perl 5.10.0: Environment for perl 5.10.0:
|
From @rgsClosing bug, since the semantics of ~~ have settled down in 5.10.1. |
@rgs - Status changed from 'new' to 'resolved' |
Migrated from rt.perl.org#50538 (status was 'resolved')
Searchable as RT50538$
The text was updated successfully, but these errors were encountered: