Skip to content

Commit

Permalink
Fix crashes in degenerate .tail(Callable)
Browse files Browse the repository at this point in the history
Phixes: #1429
  • Loading branch information
zoffixznet committed Jan 22, 2018
1 parent 44ff0a2 commit ba67597
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/core/Any-iterable-methods.pm
Expand Up @@ -1857,12 +1857,13 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
multi method tail($n) {
Seq.new(
nqp::if(
nqp::istype($n,Callable)
&& nqp::isgt_i((my $skip := -($n(0).Int)),0),
nqp::istype($n,Callable),
nqp::stmts(
(my $iterator := self.iterator).skip-at-least($skip),
$iterator
),
(my $iterator := self.iterator),
nqp::if(
nqp::isgt_i((my $skip := -($n(0).Int)),0),
$iterator.skip-at-least($skip)),
$iterator),
Rakudo::Iterator.LastNValues(self.iterator,$n,'tail')
)
)
Expand Down
8 changes: 5 additions & 3 deletions src/core/List.pm
Expand Up @@ -1456,9 +1456,11 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
nqp::stmts(
(my $iterator := Rakudo::Iterator.ReifiedList(self)),
nqp::if(
nqp::istype($n,Callable)
&& nqp::isgt_i((my $skip := -($n(0).Int)),0),
$iterator.skip-at-least($skip),
nqp::istype($n,Callable),
nqp::if(
nqp::isgt_i((my $skip := -($n(0).Int)),0),
$iterator.skip-at-least($skip)
),
nqp::unless(
nqp::istype($n,Whatever) || $n == Inf,
$iterator.skip-at-least(nqp::elems($!reified) - $n)
Expand Down

0 comments on commit ba67597

Please sign in to comment.