Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix another off-by-one error in general Range iterator
1.9 .. 3.5 should produce 1.9, 2.9. We missed the latter because we compared
with <= 2.5. So instead of calculating an end point, just use $!excludes-max
to decide whether to use < or <= for comparison.
  • Loading branch information
niner committed Aug 22, 2015
1 parent bd5cfcb commit a20db8f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/Range.pm
Expand Up @@ -170,16 +170,18 @@ my class Range is Cool does Iterable does Positional {
class :: does Iterator {
has $!i;
has $!e;
has $!exclude;

method new($i is copy, $e is copy) {
method new($i is copy, $exclude is copy, $e is copy) {
my \iter = self.CREATE;
nqp::bindattr(iter, self, '$!i', $i);
nqp::bindattr(iter, self, '$!e', $e);
nqp::bindattr(iter, self, '$!exclude', $exclude);
iter
}

method pull-one() {
if $!i <= $!e {
if $!exclude ?? $!i < $!e !! $!i <= $!e {
my Mu $i = $!i;
$!i = $i.succ;
$i
Expand All @@ -188,7 +190,7 @@ my class Range is Cool does Iterable does Positional {
IterationEnd
}
}
}.new($value, $!excludes-max ?? $!max.pred !! $!max)
}.new($value, $!excludes-max, $!max)
}
}
multi method list(Range:D:) { List.from-iterator(self.iterator) }
Expand Down

0 comments on commit a20db8f

Please sign in to comment.