Skip to content

Commit

Permalink
another typed failure from Str.substr
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jul 16, 2012
1 parent 65e2aae commit 1fe39c7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/Str.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ my class Str does Stringy {
if $istart > $ichars; if $istart > $ichars;
$length = $length($ichars - $istart) if nqp::istype($length, Callable); $length = $length($ichars - $istart) if nqp::istype($length, Callable);
my int $ilength = $length.defined ?? $length.Int !! $ichars - $istart; 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; if $ilength < 0;

nqp::p6box_s(nqp::substr($sself, $istart, $ilength)); nqp::p6box_s(nqp::substr($sself, $istart, $ilength));
} }


Expand Down

0 comments on commit 1fe39c7

Please sign in to comment.