Permalink
Browse files

another typed failure from Str.substr

  • Loading branch information...
1 parent 65e2aae commit 1fe39c7f4f078da8b64f3798bcb9893a38e75b3d @moritz moritz committed Jul 16, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/core/Str.pm
View
@@ -92,9 +92,13 @@ my class Str does Stringy {
if $istart > $ichars;
$length = $length($ichars - $istart) if nqp::istype($length, Callable);
my int $ilength = $length.defined ?? $length.Int !! $ichars - $istart;
- fail "Negative length argument ($length) to .substr, use *{$ilength} if you want relative to the end"
+ X::OutOfRange.new(
+ what => 'Length argument to substr',
+ got => $length,
+ range => (0..*),
+ comment => "use *{$ilength} if you want to index relative to the end"
+ ).fail
if $ilength < 0;
-
nqp::p6box_s(nqp::substr($sself, $istart, $ilength));
}

0 comments on commit 1fe39c7

Please sign in to comment.