diff --git a/src/core/Cool-str.pm b/src/core/Cool-str.pm index 7d97ae77695..f667a77af5b 100644 --- a/src/core/Cool-str.pm +++ b/src/core/Cool-str.pm @@ -220,21 +220,18 @@ augment class Cool { # .tailcall '!FAIL'("Attempt to index from negative position") } + # S32/Str says that this should always return a StrPos object - # our Int multi method rindex($substring, $pos?) is export { - # if ($substring.chars == 0) { - # my $string_length = self.chars; - # return $pos.defined && $pos < $string_length ?? $pos !! $string_length; - # } - # - # my $result = pir::reverse_index__ISSi(self, $substring, $pos); - # fail("Substring '$substring' not found in '{self}'") if $result < 0; - # return $result; - # - # # also used to be a the following error message, but the condition - # # was never checked: - # # .tailcall '!FAIL'("Attempt to index from negative position") - # } + our Int multi method rindex($substring, $pos?) is export { + if ($substring.chars == 0) { + my $string_length = self.chars; + return $pos.defined && $pos < $string_length ?? $pos !! $string_length; + } + + my $result = (~self).reverse_index($substring, $pos); + fail("Substring '$substring' not found in '{self}'") if $result < 0; + return $result; + } our Str multi method chop() is export { self.substr(0, -1) diff --git a/t/spectest.data b/t/spectest.data index c813fd06e92..1410832446d 100644 --- a/t/spectest.data +++ b/t/spectest.data @@ -560,7 +560,7 @@ S32-str/lc.t # icu # S32-str/p5chomp.t S32-str/p5chop.t S32-str/pos.t -# S32-str/rindex.t +S32-str/rindex.t S32-str/samecase.t # icu # S32-str/split-simple.t S32-str/split-simple2.t # CHEAT! simplified version of split-simple.t