Bug#691102: perl: Any ~~ Object smartmatch precedence broken
Niko Tyni
ntyni at debian.org
Sun Oct 21 14:08:53 UTC 2012
Package: perl
Version: 5.14.2-14
Severity: important
Tags: patch fixed-upstream
Perl 5.14.3 included the attached patch, which fixes incorrect smartmatch
precedence.
$ perl -lwe '{ package A; use overload "~~" => sub { print "in overloaded match A"; }; } { package B; use overload "~~" => sub { print "in overloaded match B"; }; } my $a=bless({},"A"); my $b=bless({},"B"); print $a ~~ $b'
in overloaded match A
1
According to the documented behaviour, the first line should be
in overloaded match B
There's some background at
http://www.nntp.perl.org/group/perl.perl5.porters/2011/07/msg174260.html
where the upstream consensus is clearly that this is a misfeature that
nobody should be counting on and works against the current documentation.
The patch removes two incorrect test cases; quoting Leon Timmermans in
the thread:
>> It fixes the issue but
>> makes two tests in t/op/smartmatch.t fail. It creates a failure if you
>> match an object with smartmatch overloading with an object that has
>> overloading but not for smartmatching (in case of the test,
>> stringification overloading). I'm not sure that case is sane to begin
>> with though.
>
> IMO, in this case following the left hand (the current behavior) is
> simply insane, for reasons Ricardo already explained. Following the
> right hand if it doesn't overload smartmatching is simply impossible:
> it can't know if it should use the code, hash, regexp, array, string
> or number overloading. Making this obscure use-case die is the only
> possible sane thing we can do.
The issue isn't a regression from squeeze, but we think it should be
fixed rather sooner than later, on the principle of least surprise.
--
Niko Tyni ntyni at debian.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Enforce-Any-Object-smartmatch-precedence.patch
Type: text/x-diff
Size: 1353 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/perl-maintainers/attachments/20121021/6022e7a0/attachment.patch>
More information about the Perl-maintainers
mailing list