Skip to content

Commit

Permalink
Fix regression in Range.int-bounds
Browse files Browse the repository at this point in the history
Yesterday's fix[^1] to the method assumed an .Int on endpoints will be
False only if the conversion returns a Failure, but it's possible to
construct a non-int Range with `0` as one of the end-points, whose
.Int is False.

Fix by adding additional type checks that .Int's are Int

[1] 79f2681004224108b2acd18bec2
  • Loading branch information
zoffixznet committed Mar 17, 2017
1 parent 79f2681 commit 16ef21c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/Range.pm
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ my class Range is Cool does Iterable does Positional {
nqp::istype($!min,Real)
&& $!min.floor == $!min
&& nqp::istype($!max,Real)
&& $!min.Int && $!max.Int, # exclude NaN and Infs, who will fail() here
&& nqp::istype($!min.Int, Int) # exclude NaN and Infs, who will fail() here
&& nqp::istype($!max.Int, Int),
nqp::stmts(
($from = $!min.floor + $!excludes-min),
($to = $!max.floor - ($!excludes-max && $!max.Int == $!max))
Expand All @@ -395,7 +396,8 @@ my class Range is Cool does Iterable does Positional {
$!is-int
?? ($!min + $!excludes-min, $!max - $!excludes-max)
!! nqp::istype($!min,Real) && $!min.floor == $!min && nqp::istype($!max,Real)
&& $!min.Int && $!max.Int # exclude NaN and Infs, who will fail() here
&& nqp::istype($!min.Int, Int) # exclude NaN and Infs, who will fail() here
&& nqp::istype($!max.Int, Int)
?? ($!min.floor + $!excludes-min, $!max.floor - ($!excludes-max && $!max.Int == $!max))
!! Failure.new("Cannot determine integer bounds")
}
Expand Down

0 comments on commit 16ef21c

Please sign in to comment.