Skip to content

Commit

Permalink
Make sure Seq.reverse fails on lazy iterators
Browse files Browse the repository at this point in the history
That was one thing the previous Seq.list.reverse path did do, but
now we check without trying to reify.
  • Loading branch information
lizmat committed Apr 30, 2020
1 parent cea0fc7 commit 4025ca4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core.c/Seq.pm6
Expand Up @@ -111,8 +111,14 @@ my class Seq is Cool does Iterable does Sequence {
}

method reverse(--> Seq:D) {
self.iterator.push-all(my \buffer := nqp::create(IterationBuffer));
Seq.new: Rakudo::Iterator.ReifiedListReverse(buffer)
nqp::if(
(my $iterator := self.iterator).is-lazy,
Failure.new(X::Cannot::Lazy.new(:action<reverse>)),
nqp::stmts(
$iterator.push-all(my \buffer := nqp::create(IterationBuffer)),
Seq.new: Rakudo::Iterator.ReifiedListReverse(buffer)
)
)
}

method sink(--> Nil) {
Expand Down

0 comments on commit 4025ca4

Please sign in to comment.