Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add <0 test to Parcel.at_pos
  • Loading branch information
lizmat committed Jan 15, 2015
1 parent 7af6a8b commit a151332
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/core/Parcel.pm
Expand Up @@ -113,13 +113,25 @@ my class Parcel does Positional { # declared in BOOTSTRAP
}

multi method at_pos(Parcel:D: int \pos) is rw {
nqp::isge_i(pos,nqp::elems($!storage)) || nqp::islt_i(pos,0)
X::OutOfRange.new(
:what<Index>,
:got(pos),
:range(Range.new(0,Inf))
).throw
if nqp::islt_i(pos,0);
nqp::isge_i(pos,nqp::elems($!storage))
?? Nil
!! nqp::atpos($!storage,pos);
}
multi method at_pos(Parcel:D: Int:D \pos) is rw {
my int $pos = nqp::unbox_i(pos);
nqp::isge_i($pos,nqp::elems($!storage)) || nqp::islt_i($pos,0)
X::OutOfRange.new(
:what<Index>,
:got(pos),
:range(Range.new(0,Inf))
).throw
if nqp::islt_i($pos,0);
nqp::isge_i($pos,nqp::elems($!storage))
?? Nil
!! nqp::atpos($!storage,$pos);
}
Expand Down

0 comments on commit a151332

Please sign in to comment.