Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.substr on a string built with infix:<x> gives the wrong result in Rakudo on Moar #3646

Closed
p6rt opened this issue Jan 15, 2015 · 6 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Jan 15, 2015

Migrated from rt.perl.org#123602 (status was 'resolved')

Searchable as RT123602$

@p6rt
Copy link
Author

p6rt commented Jan 15, 2015

From @masak

<masak> wow, this is the worst rakudobug I've had in a while.
<masak> m​: for 2, 3 -> $n { my $s = "0" x $n ~ "1"; say $s, "​: ",
$s.substr(0, 1) ~ "1" ~ $s.substr(2) }
<camelia> rakudo-moar 0bb3ad​: OUTPUT«001​: 011␤0001​: 0100␤»
<masak> just stare at that for a while.
<masak> that last expression with the .substr calls essentially means
"put in a 1 in the second place, but leave everything else intact".
<masak> well, if that is so, where did the final "1" go in "0001"?
* masak submits rakudobug
<masak> p6​: for 2, 3 -> $n { my $s = "0" x $n ~ "1"; say $s, "​: ",
$s.substr(0, 1) ~ "1" ~ $s.substr(2) }
<camelia> rakudo-parrot 0bb3ad​: OUTPUT«001​: 011␤0001​: 0101␤»
<camelia> ..rakudo-moar 0bb3ad​: OUTPUT«001​: 011␤0001​: 0100␤»
<masak> right.
<masak> since I know a tiny bit about how strings are implemented on
Moar, I predict that the bug will be tracked down in how string
repetitions are handled.
<masak> p6​: say ("0" x 3 ~ "1").substr(2)
<camelia> rakudo-moar 0bb3ad​: OUTPUT«00␤»
<camelia> ..rakudo-parrot 0bb3ad​: OUTPUT«01␤»
<masak> even golfer.

@p6rt
Copy link
Author

p6rt commented Mar 13, 2015

From @usev6

Î added a test (fudged 'todo' for MoarVM) for the last example to S32-str/substr.t with commit Raku/roast@cf04ac010e.

@p6rt
Copy link
Author

p6rt commented Mar 13, 2015

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 10, 2016

From @zoffixznet

Still present on rakudo 89470a​:

<Zoffix> m​: for 2, 3 -> $n { my $s = "0" x $n ~ "1"; say $s, "​: ", $s.substr(0, 1) ~ "1" ~ $s.substr(2) }
<camelia> rakudo-moar 89470a​: OUTPUT«001​: 011␤0001​: 0100␤»

@p6rt
Copy link
Author

p6rt commented Jul 21, 2016

From @jnthn

On Thu Jan 15 06​:36​:57 2015, masak wrote​:

<masak> since I know a tiny bit about how strings are implemented on
Moar, I predict that the bug will be tracked down in how string
repetitions are handled.

It was exactly that. There is a fast path for jumping through strands and repetitions to the correct point, and it failed to account for the fact that the next char you read would come from the *next* repetition that we didn't fully skip over, leading to an off-by-one.

<masak> p6​: say ("0" x 3 ~ "1").substr(2)
<camelia> rakudo-moar 0bb3ad​: OUTPUT«00␤»
<camelia> ..rakudo-parrot 0bb3ad​: OUTPUT«01␤»
<masak> even golfer.

Test in S32-str/substr.t unfudged to cover this.

@p6rt
Copy link
Author

p6rt commented Jul 21, 2016

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Jul 21, 2016
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant