Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure delete attempts past end of array doesn't vivify

  • Loading branch information...
commit 85b9a40e1562378b2b6139c9933c3bec3412b512 1 parent d185d53
@lizmat lizmat authored
Showing with 9 additions and 5 deletions.
  1. +8 −4 src/core/Array.pm
  2. +1 −1  src/core/List.pm
View
12 src/core/Array.pm
@@ -70,20 +70,24 @@ class Array { # declared in BOOTSTRAP
self.delete_pos(pos);
}
method delete_pos(\pos) {
- return Nil if pos < 0;
+ fail "Cannot use negative index {pos} on {self.WHAT.perl}" if pos < 0;
- my $value := self.at_pos(pos);
+ my $value := self.at_pos(pos); # needed for reification
my $items := nqp::getattr(self,List,'$!items');
+ my $end := self.end;
- if pos == self.end {
+ if pos == $end {
my $pos = pos;
nqp::pop($items);
nqp::pop($items)
while --$pos >= 0 && nqp::isnull(nqp::atpos($items,$pos));
}
- else {
+ elsif pos < $end {
nqp::bindpos($items, pos, nqp::null());
}
+ else {
+ return self.default;
+ }
$value;
}
View
2  src/core/List.pm
@@ -77,7 +77,7 @@ my class List does Positional { # declared in BOOTSTRAP
$pos = $pos.Int;
self.exists_pos($pos)
?? nqp::atpos($!items, nqp::unbox_i($pos))
- !! Nil
+ !! Nil;
}
multi method at_pos(List:D: int $pos) is rw {
self.exists_pos($pos)
Please sign in to comment.
Something went wrong with that request. Please try again.