Skip Menu |

This queue is for tickets about the match-simple CPAN distribution.

Report information
The Basics
Id: 117345
Status: resolved
Priority: 0/
Queue: match-simple

People
Owner: perl [...] toby.ink
Requestors: danboo [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.009
Fixed in: (no value)



Subject: match::smart::match(ARRAY,ARRAY) short circuiting
Consider the following smart match comparisons of two arrays of strings. My expectation is that they will be considered non-matching since the second values in each are not equal. The built-in '~~' agrees with my expectations: Show quoted text
> perl -E 'my $c = [ 1,2 ]; my $d = [ 1,3 ]; say $c ~~ $d ? q(match) : q(no-match)'
no-match But the module match() subroutine considers them matching even though the second element differs: Show quoted text
> perl -Mlocal::lib -Mmatch::smart=match -E 'my $c = [ 1,2 ]; my $d = [ 1,3 ]; say match( $c, $d ) ? q(match) : q(no-match)'
From reviewing the match::smart::match() code this appears to relate to how $seen tracks the refaddr() of $b. After match() recurses and starts iterating over the array values, when $b contains '2', the refaddr() is 'undef', and it increments $seen{undef}. On the second iteration, when $b contains '3', refaddr() is again undef, which already exists in $seen, triggering a short-circuit that returns true since refaddr() of both values is undef. return refaddr($a)==refaddr($b) if $seen->{refaddr($b)}++;
On Tue Aug 30 17:25:29 2016, DANBOO wrote: Show quoted text
> Consider the following smart match comparisons of two arrays of > strings. My expectation is that they will be considered non-matching
Oops, that should be "arrays of numbers". My initial example had strings, but then I changed it to numbers and forgot to update the description. Either strings or numbers will trigger the issue obviously.
Fixed in 0.010.