Skip to content

Commit

Permalink
Fix .first on Numerics
Browse files Browse the repository at this point in the history
The logic in the method uses `+self` to get number of elements in
the list, however, `self` is not guaranteed to be a list and may be
a Numeric type, in which case we get an incorrect number.

Fix by using `self.elems` instead.

Bug find: https://irclog.perlgeek.de/perl6/2016-12-08#i_13705826
  • Loading branch information
zoffixznet committed Dec 8, 2016
1 parent 7511b43 commit 8cb3e1b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/Any-iterable-methods.pm
Expand Up @@ -1126,7 +1126,7 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
proto method first(|) is nodal { * }
multi method first(:$end) {
$end
?? ((my $elems = +self) ?? self.AT-POS($elems - 1) !! Nil)
?? ((my $elems = self.elems) ?? self.AT-POS($elems - 1) !! Nil)
!! ((my $x := self.iterator.pull-one) =:= IterationEnd ?? Nil !! $x)
}
multi method first(Bool:D $t) {
Expand All @@ -1141,7 +1141,7 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
multi method first(Callable:D $test, :$end, *%a is copy) is raw {
if $end {
nqp::stmts(
(my $elems = +self),
(my $elems = self.elems),
nqp::if(
($elems && nqp::not_i($elems == Inf)),
nqp::stmts(
Expand Down Expand Up @@ -1200,7 +1200,7 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
}
method !first-accepts-end(Mu $test,%a) is raw {
nqp::stmts(
(my $elems = +self),
(my $elems = self.elems),
nqp::if(
($elems && nqp::not_i($elems == Inf)),
nqp::stmts(
Expand Down

0 comments on commit 8cb3e1b

Please sign in to comment.