Skip Menu |
Report information
Id: 129248
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: jan-olof.hendig [at] bredband.net
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: "Jan-Olof Hendig" <jan-olof.hendig [...] bredband.net>
Subject: [BUG] Str.rindex returns error messages with missing or incorrect information
To: <rakudobug [...] perl.org>
Date: Sun, 11 Sep 2016 16:58:35 +0200
# Tested with dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -v This is Rakudo version 2016.08.1-155-gccecbfe built on MoarVM version 2016.08-43-g3d04391 implementing Perl 6.c. # the first problem dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say "1234".rindex("2", -1)' Position in rindex out of range. Is: -1, should be in 0..4 in block <unit> at -e line 1 Actually thrown at: in block <unit> at -e line 1 # the position given *IS* out of range but the suggestion given, i.e. "should be in 0..4" is incorrect since the string only contains four chars # let us test the suggestion and use 4 as the position dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say "1234".rindex("2", 4)' index start offset out of range in block <unit> at -e line 1 # this also failed but this time we got no extra information, i.e. "Position in rindex out of range. Bla bla" # according to timo this could possibly point to a problem in MoarVM See http://irclog.perlgeek.de/perl6/2016-09-10#i_13185974 /dogbert17
Subject: Re: [perl #129248] [BUG] Str.rindex returns error messages with missing or incorrect information
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Date: Sun, 11 Sep 2016 21:36:55 +0200
To: "Jan-Olof Hendig (via RT)" <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 1.5k
Oddly enough, index() does *not* have this issue: $ 6 'say "1234".index("2", 4)’ Nil Not sure that’s a bug either. Show quoted text
> On 11 Sep 2016, at 16:58, Jan-Olof Hendig (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Jan-Olof Hendig > # Please include the string: [perl #129248] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=129248 > > > > # Tested with > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -v This is Rakudo > version 2016.08.1-155-gccecbfe built on MoarVM version 2016.08-43-g3d04391 > implementing Perl 6.c. > > # the first problem > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > "1234".rindex("2", -1)' > Position in rindex out of range. Is: -1, should be in 0..4 > in block <unit> at -e line 1 > > Actually thrown at: > in block <unit> at -e line 1 > > # the position given *IS* out of range but the suggestion given, i.e. > "should be in 0..4" is incorrect since the string only contains four chars # > let us test the suggestion and use 4 as the position > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > "1234".rindex("2", 4)' > index start offset out of range > in block <unit> at -e line 1 > > # this also failed but this time we got no extra information, i.e. "Position > in rindex out of range. Bla bla" > # according to timo this could possibly point to a problem in MoarVM > > See http://irclog.perlgeek.de/perl6/2016-09-10#i_13185974 > > /dogbert17 > >
Date: Sun, 11 Sep 2016 23:09:16 +0200
To: <perl6-bugs-followup [...] perl.org>
Subject: RE: [perl #129248] [BUG] Str.rindex returns error messages with missing or incorrect information
From: "Jan-Olof Hendig" <jan-olof.hendig [...] bredband.net>
Download (untitled) / with headers
text/plain 2.1k
They do indeed behave somewhat inconsistently when the position is too high. Consistency, and the off by one error, returns when using -1 though. dogbert@dogbert-VirtualBox ~/repos/doc $ perl6 -e 'say "1234".index("2", -1)' Position in index out of range. Is: -1, should be in 0..4 in block <unit> at -e line 1 Actually thrown at: in block <unit> at -e line 1 Show quoted text
-----Original Message----- From: Elizabeth Mattijsen via RT [mailto:perl6-bugs-followup@perl.org] Sent: den 11 september 2016 21:38 To: jan-olof.hendig@bredband.net Subject: Re: [perl #129248] [BUG] Str.rindex returns error messages with missing or incorrect information Oddly enough, index() does *not* have this issue: $ 6 'say "1234".index("2", 4)’ Nil Not sure that’s a bug either.
> On 11 Sep 2016, at 16:58, Jan-Olof Hendig (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Jan-Olof Hendig # Please include the string: > [perl #129248] # in the subject line of all future correspondence > about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=129248 > > > > # Tested with > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -v This is > Rakudo version 2016.08.1-155-gccecbfe built on MoarVM version > 2016.08-43-g3d04391 implementing Perl 6.c. > > # the first problem > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > "1234".rindex("2", -1)' > Position in rindex out of range. Is: -1, should be in 0..4 in block > <unit> at -e line 1 > > Actually thrown at: > in block <unit> at -e line 1 > > # the position given *IS* out of range but the suggestion given, i.e. > "should be in 0..4" is incorrect since the string only contains four > chars # let us test the suggestion and use 4 as the position > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > "1234".rindex("2", 4)' > index start offset out of range > in block <unit> at -e line 1 > > # this also failed but this time we got no extra information, i.e. > "Position in rindex out of range. Bla bla" > # according to timo this could possibly point to a problem in MoarVM > > See http://irclog.perlgeek.de/perl6/2016-09-10#i_13185974 > > /dogbert17 > >
Download (untitled) / with headers
text/plain 3.6k
On Mon Sep 12 13:56:24 2016, jan-olof.hendig@bredband.net wrote: Show quoted text
> They do indeed behave somewhat inconsistently when the position is too > high. Consistency, and the off by one error, returns when using -1 > though. > > dogbert@dogbert-VirtualBox ~/repos/doc $ perl6 -e 'say > "1234".index("2", -1)' > Position in index out of range. Is: -1, should be in 0..4 > in block <unit> at -e line 1 > > Actually thrown at: > in block <unit> at -e line 1 > > > -----Original Message----- > From: Elizabeth Mattijsen via RT [mailto:perl6-bugs- > followup@perl.org] > Sent: den 11 september 2016 21:38 > To: jan-olof.hendig@bredband.net > Subject: Re: [perl #129248] [BUG] Str.rindex returns error messages > with missing or incorrect information > > Oddly enough, index() does *not* have this issue: > > $ 6 'say "1234".index("2", 4)’ > Nil > > Not sure that’s a bug either. >
> > On 11 Sep 2016, at 16:58, Jan-Olof Hendig (via RT) <perl6-bugs- > > followup@perl.org> wrote: > > > > # New Ticket Created by Jan-Olof Hendig # Please include the string: > > [perl #129248] # in the subject line of all future correspondence > > about this issue. > > # <URL: https://rt.perl.org/Ticket/Display.html?id=129248 > > > > > > > # Tested with > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -v This is > > Rakudo version 2016.08.1-155-gccecbfe built on MoarVM version > > 2016.08-43-g3d04391 implementing Perl 6.c. > > > > # the first problem > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > > "1234".rindex("2", -1)' > > Position in rindex out of range. Is: -1, should be in 0..4 in block > > <unit> at -e line 1 > > > > Actually thrown at: > > in block <unit> at -e line 1 > > > > # the position given *IS* out of range but the suggestion given, i.e. > > "should be in 0..4" is incorrect since the string only contains four > > chars # let us test the suggestion and use 4 as the position > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > > "1234".rindex("2", 4)' > > index start offset out of range > > in block <unit> at -e line 1 > > > > # this also failed but this time we got no extra information, i.e. > > "Position in rindex out of range. Bla bla" > > # according to timo this could possibly point to a problem in MoarVM > > > > See http://irclog.perlgeek.de/perl6/2016-09-10#i_13185974 > > > > /dogbert17 > > > >
Roast has a test for index and rindex that implies the 1..4 range in this bug's example is correct. In S32-str/index.t is this test: is(index("Hello", "", 5), 5, "Substr is empty, pos at end of str"); In S32-str/rindex.t is this test: is(rindex("Hello", "", 5), 5, "Substr is empty, pos at end of str"); To expand on the inconsistency between index and rindex, "1234".index("", 5) and "1234".index("2", 5) both return Nil, and so does "1234".rindex("", 5), but "1234".rindex("2", 5) fails with "index start offset out of range". This inconsistency is passed through from nqp, where nqp::index("1234", "", 5) and nqp::index("1234", "2", 5) both return -1, but nqp::rindex("1234", "", 5) returns -1 and nqp::rindex("1234", "2", 5) fails with "index start offset out of range". And the real source of the inconsistency is in MoarVM like timotimo said in the chat log. MVM_string_index_from_end in src/string.ops.c has: if (start < 0 || start >= hgraphs) /* maybe return -1 instead? */ MVM_exception_throw_adhoc(tc, "index start offset out of range"); but MVM_string_index has: if (start < 0 || start >= hgraphs) return -1; What should the Perl 6 behavior be? Return Nil when it's a little bit out of range and a Failure if it's a lot out of range? Or return either Nil or Failure if it's at all out of range?
On Mon Sep 19 23:30:20 2016, ddgreen@gmail.com wrote: Show quoted text
> On Mon Sep 12 13:56:24 2016, jan-olof.hendig@bredband.net wrote:
> > They do indeed behave somewhat inconsistently when the position is > > too > > high. Consistency, and the off by one error, returns when using -1 > > though. > > > > dogbert@dogbert-VirtualBox ~/repos/doc $ perl6 -e 'say > > "1234".index("2", -1)' > > Position in index out of range. Is: -1, should be in 0..4 > > in block <unit> at -e line 1 > > > > Actually thrown at: > > in block <unit> at -e line 1 > > > > > > -----Original Message----- > > From: Elizabeth Mattijsen via RT [mailto:perl6-bugs- > > followup@perl.org] > > Sent: den 11 september 2016 21:38 > > To: jan-olof.hendig@bredband.net > > Subject: Re: [perl #129248] [BUG] Str.rindex returns error messages > > with missing or incorrect information > > > > Oddly enough, index() does *not* have this issue: > > > > $ 6 'say "1234".index("2", 4)’ > > Nil > > > > Not sure that’s a bug either. > >
> > > On 11 Sep 2016, at 16:58, Jan-Olof Hendig (via RT) <perl6-bugs- > > > followup@perl.org> wrote: > > > > > > # New Ticket Created by Jan-Olof Hendig # Please include the > > > string: > > > [perl #129248] # in the subject line of all future correspondence > > > about this issue. > > > # <URL: https://rt.perl.org/Ticket/Display.html?id=129248 > > > > > > > > > > # Tested with > > > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -v This > > > is > > > Rakudo version 2016.08.1-155-gccecbfe built on MoarVM version > > > 2016.08-43-g3d04391 implementing Perl 6.c. > > > > > > # the first problem > > > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > > > "1234".rindex("2", -1)' > > > Position in rindex out of range. Is: -1, should be in 0..4 in > > > block > > > <unit> at -e line 1 > > > > > > Actually thrown at: > > > in block <unit> at -e line 1 > > > > > > # the position given *IS* out of range but the suggestion given, > > > i.e. > > > "should be in 0..4" is incorrect since the string only contains > > > four > > > chars # let us test the suggestion and use 4 as the position > > > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > > > "1234".rindex("2", 4)' > > > index start offset out of range > > > in block <unit> at -e line 1 > > > > > > # this also failed but this time we got no extra information, i.e. > > > "Position in rindex out of range. Bla bla" > > > # according to timo this could possibly point to a problem in > > > MoarVM > > > > > > See http://irclog.perlgeek.de/perl6/2016-09-10#i_13185974 > > > > > > /dogbert17 > > > > > >
> > > Roast has a test for index and rindex that implies the 1..4 range in > this bug's example is correct. > In S32-str/index.t is this test: is(index("Hello", "", 5), 5, "Substr > is empty, pos at end of str"); > In S32-str/rindex.t is this test: is(rindex("Hello", "", 5), 5, > "Substr is empty, pos at end of str"); > > To expand on the inconsistency between index and rindex, > "1234".index("", 5) and "1234".index("2", 5) both return Nil, and so > does "1234".rindex("", 5), but "1234".rindex("2", 5) fails with "index > start offset out of range". > > This inconsistency is passed through from nqp, where > nqp::index("1234", "", 5) and nqp::index("1234", "2", 5) both return > -1, but nqp::rindex("1234", "", 5) returns -1 and nqp::rindex("1234", > "2", 5) fails with "index start offset out of range". > > And the real source of the inconsistency is in MoarVM like timotimo > said in the chat log. MVM_string_index_from_end in src/string.ops.c > has: > if (start < 0 || start >= hgraphs) > /* maybe return -1 instead? */ > MVM_exception_throw_adhoc(tc, "index start offset out of range"); > > but MVM_string_index has: > if (start < 0 || start >= hgraphs) > return -1; > > What should the Perl 6 behavior be? Return Nil when it's a little bit > out of range and a Failure if it's a lot out of range? Or return > either Nil or Failure if it's at all out of range?
Adding [@LARRY] per http://irclog.perlgeek.de/perl6-dev/2016-09-22#i_13254766
Download (untitled) / with headers
text/plain 5.2k
On Thu Sep 22 04:39:30 2016, ddgreen@gmail.com wrote: Show quoted text
> On Mon Sep 19 23:30:20 2016, ddgreen@gmail.com wrote:
> > On Mon Sep 12 13:56:24 2016, jan-olof.hendig@bredband.net wrote:
> > > They do indeed behave somewhat inconsistently when the position is > > > too > > > high. Consistency, and the off by one error, returns when using -1 > > > though. > > > > > > dogbert@dogbert-VirtualBox ~/repos/doc $ perl6 -e 'say > > > "1234".index("2", -1)' > > > Position in index out of range. Is: -1, should be in 0..4 > > > in block <unit> at -e line 1 > > > > > > Actually thrown at: > > > in block <unit> at -e line 1 > > > > > > > > > -----Original Message----- > > > From: Elizabeth Mattijsen via RT [mailto:perl6-bugs- > > > followup@perl.org] > > > Sent: den 11 september 2016 21:38 > > > To: jan-olof.hendig@bredband.net > > > Subject: Re: [perl #129248] [BUG] Str.rindex returns error messages > > > with missing or incorrect information > > > > > > Oddly enough, index() does *not* have this issue: > > > > > > $ 6 'say "1234".index("2", 4)’ > > > Nil > > > > > > Not sure that’s a bug either. > > >
> > > > On 11 Sep 2016, at 16:58, Jan-Olof Hendig (via RT) <perl6-bugs- > > > > followup@perl.org> wrote: > > > > > > > > # New Ticket Created by Jan-Olof Hendig # Please include the > > > > string: > > > > [perl #129248] # in the subject line of all future correspondence > > > > about this issue. > > > > # <URL: https://rt.perl.org/Ticket/Display.html?id=129248 > > > > > > > > > > > > > # Tested with > > > > > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -v This > > > > is > > > > Rakudo version 2016.08.1-155-gccecbfe built on MoarVM version > > > > 2016.08-43-g3d04391 implementing Perl 6.c. > > > > > > > > # the first problem > > > > > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > > > > "1234".rindex("2", -1)' > > > > Position in rindex out of range. Is: -1, should be in 0..4 in > > > > block > > > > <unit> at -e line 1 > > > > > > > > Actually thrown at: > > > > in block <unit> at -e line 1 > > > > > > > > # the position given *IS* out of range but the suggestion given, > > > > i.e. > > > > "should be in 0..4" is incorrect since the string only contains > > > > four > > > > chars # let us test the suggestion and use 4 as the position > > > > > > > > dogbert@dogbert-VirtualBox ~/.rakudobrew/moar-nom $ perl6 -e 'say > > > > "1234".rindex("2", 4)' > > > > index start offset out of range > > > > in block <unit> at -e line 1 > > > > > > > > # this also failed but this time we got no extra information, > > > > i.e. > > > > "Position in rindex out of range. Bla bla" > > > > # according to timo this could possibly point to a problem in > > > > MoarVM > > > > > > > > See http://irclog.perlgeek.de/perl6/2016-09-10#i_13185974 > > > > > > > > /dogbert17 > > > > > > > >
> > > > > > Roast has a test for index and rindex that implies the 1..4 range in > > this bug's example is correct. > > In S32-str/index.t is this test: is(index("Hello", "", 5), 5, "Substr > > is empty, pos at end of str"); > > In S32-str/rindex.t is this test: is(rindex("Hello", "", 5), 5, > > "Substr is empty, pos at end of str"); > > > > To expand on the inconsistency between index and rindex, > > "1234".index("", 5) and "1234".index("2", 5) both return Nil, and so > > does "1234".rindex("", 5), but "1234".rindex("2", 5) fails with > > "index > > start offset out of range". > > > > This inconsistency is passed through from nqp, where > > nqp::index("1234", "", 5) and nqp::index("1234", "2", 5) both return > > -1, but nqp::rindex("1234", "", 5) returns -1 and nqp::rindex("1234", > > "2", 5) fails with "index start offset out of range". > > > > And the real source of the inconsistency is in MoarVM like timotimo > > said in the chat log. MVM_string_index_from_end in src/string.ops.c > > has: > > if (start < 0 || start >= hgraphs) > > /* maybe return -1 instead? */ > > MVM_exception_throw_adhoc(tc, "index start offset out of range"); > > > > but MVM_string_index has: > > if (start < 0 || start >= hgraphs) > > return -1; > > > > What should the Perl 6 behavior be? Return Nil when it's a little bit > > out of range and a Failure if it's a lot out of range? Or return > > either Nil or Failure if it's at all out of range?
> > > Adding [@LARRY] per http://irclog.perlgeek.de/perl6-dev/2016-09- > 22#i_13254766
Adding comments from a conversation with TimToady (http://irclog.perlgeek.de/perl6/2016-09-26#i_13285140) 16:28 TimToady_ MasterDuke_: rindex is not symmetrical with index, since positions are measured from the start of the needle, not the end, so I'd say the rindex("1234","2",4) should fail indicating the correct range is 0..3, since the actual allowed range is not 0 .. 4 but rather 0 .. 4 - $needle.chars 16:29 TimToady_ MasterDuke_: though I suppose we could just return Nil up through 4 just for convenience 16:30 TimToady_ MasterDuke_: or we could say that if they give us a position within the string that is too long to match, we just force it to the first position that could match 16:31 TimToady_ such that rindex("1234","2",4) would simply return 1, and rindex("1234","2",5) would report failure 16:31 and then it wouldn't matter if it said 0..3 or 0..4 16:33 TimToady_ MasterDuke_: so I think the last thing I said is probably the best approach


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org