atom feed1 message in org.perl.perl5-porters[perl #50538] when( @n && %n ) fails ...
FromSent OnAttachments
brian d foyFeb 4, 2008 7:35 pm 
Subject:[perl #50538] when( @n && %n ) fails to smart match
From:brian d foy (perl@perl.org)
Date:Feb 4, 2008 7:35:38 pm
List:org.perl.perl5-porters

# New Ticket Created by "brian d foy" # Please include the string: [perl #50538] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=50538 >

This is a bug report for perl from bria@gmail.com, generated with the help of perlbug 1.35 running under perl v5.10.0.

----------------------------------------------------------------- [Please enter your report here]

I first mentioned this on p5p in " Clarifying smart match behaviour in when( ... && ... )" at http://groups.google.com/group/perl.perl5.porters/browse_thread/thread/5f5d24422227e57a/2c2aa46cdeabcbcc?lnk=st&q=smart+match+foy#2c2aa46cdeabcbcc

With && in a when() and when both arguments are arrays and hashes, the smart match doesn't come out right. If it is coming out right, then there needs to be a doc fix. No one has spoken up to say it should be one way or the other.

Here's a patch to t/op/switch.t that tests the problem in three different cases:

--- 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 }

[Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=high --- This perlbug was built using Perl v5.8.8 - Mon Apr 9 10:35:38 CDT 2007 It is being executed now by Perl v5.10.0 - Sun Dec 2 12:12:45 CST 2007.

Site configuration information for perl v5.10.0:

Configured by brian at Sun Dec 2 12:12:45 CST 2007.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration: Platform: osname=darwin, osvers=8.10.1, archname=darwin-2level uname='darwin alexandria2-10.nyc.access.net 8.10.1 darwin kernel version 8.10.1: wed may 23 16:33:00 pdt 2007; root:xnu-792.22.5~1release_i386 i386 i386 ' config_args='' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include', optimize='-O3', cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include' ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build 5363)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -L/usr/local/lib -L/opt/local/lib' libpth=/usr/local/lib /opt/local/lib /usr/lib libs=-ldbm -ldl -lm -lc perllibs=-ldl -lm -lc libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib'

Locally applied patches: