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

Scoping bug with xx #3348

Closed
p6rt opened this issue Feb 26, 2014 · 5 comments
Closed

Scoping bug with xx #3348

p6rt opened this issue Feb 26, 2014 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Feb 26, 2014

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

Searchable as RT121327$

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

From @masak

<grondilu> rn​: for ^2 { my @​b = (^256).roll(64); say :256[@​b.shift xx
4] xx @​b/4; }
<camelia> ..rakudo-moar 974d00​: OUTPUT«1579205690 1355821393
4232504958 2412195070 1054437615 566464174 2486826669 1595923990
991953772 3480634857 424925589 1958990192 3384319984 1422756466
3635660521 4253976283␤===SORRY!===␤Element shifted from empty list␤»
<camelia> ..rakudo-parrot 974d00​: OUTPUT«3795212420 3158342417
256165518 1657595798 1786761498 312951935 78079993 1942245667
645834118 4081510027 2310301881 1916196990 4244084058 2864670074
2128534466 370168813␤2347852200 3952915263 1159181934 3552185973
2361045754 3404705198 1276420302 26816…»
<grondilu> « ===SORRY!===␤Element shifted from empty list » was very
much unexpected here.
<masak> m​: for ^2 { my @​b = 1 xx 4; say (@​b.shift xx 2) xx 2 }
<camelia> rakudo-moar 974d00​: OUTPUT«1 1 1 1␤===SORRY!===␤Element
shifted from empty list␤»
<masak> that sort of highlights that something is wrong, don't it?
<grondilu> indeed
<masak> m​: my @​b = 1 xx 4; say (@​b.shift xx 2) xx 2
<camelia> rakudo-moar 974d00​: OUTPUT«1 1 1 1␤»
<masak> huh!
<grondilu> it works in the first iteration, but not in the second. Go figure.
<masak> grondilu​: oh yes, that's it.
* masak submits rakudobug
<masak> m​: for ^2 { my @​b = 1 xx 4; say @​b.shift xx 4 }
<camelia> rakudo-moar 974d00​: OUTPUT«1 1 1 1␤1 1 1 1␤»
<TimToady> m​: for ^2 { my @​b = 1 xx 4; say @​b.elems; say (@​b.shift xx 2) xx 2 }
<camelia> rakudo-moar 974d00​: OUTPUT«4␤1 1 1 1␤4␤===SORRY!===␤Element
shifted from empty list␤»
<TimToady> m​: for ^2 { my @​b = 1 xx 4; say (@​b.shift; @​b.shift) xx 2 }
<camelia> rakudo-moar 974d00​: OUTPUT«1 1␤1 1␤»
<TimToady> m​: for ^2 { my @​b = 1 xx 4; say (@​b.shift xx 2) for 1..2 }
<camelia> rakudo-moar 974d00​: OUTPUT«1 1␤1 1␤===SORRY!===␤Element
shifted from empty list␤»
<TimToady> m​: for ^2 { my @​b = 1 xx 4; (say "X" xx 2) for 1..2 }
<camelia> rakudo-moar 974d00​: OUTPUT«X X␤X X␤X X␤X X␤»
<TimToady> that seems okay
<masak> yes, it's only shifting that somehow gets an old @​b or something.
<masak> this seems very much like a lexical bug to me.
* masak shudders
<grondilu> it's weird though, since as TimToady shown, @​b is correctly
4 long at the beginning of the second iteration.
<grondilu> m​: for ^2 { say my @​b = 1 xx 4; (@​b.shift xx 2) xx 2 }
<camelia> rakudo-moar 974d00​: OUTPUT«1 1 1 1␤1 1 1 1␤»
<grondilu> m​: for ^2 { say my @​b = 1 xx 4; say (@​b.shift xx 2) xx 2 }
<camelia> rakudo-moar 974d00​: OUTPUT«1 1 1 1␤1 1 1 1␤1 1 1
1␤===SORRY!===␤Element shifted from empty list␤»
<grondilu> oh, it's only when we say it that it gets wrong
<grondilu> m​: for ^2 { my @​b = 1 xx 4; my @​c = (@​b.shift xx 2) xx 2; say @​c }
<camelia> rakudo-moar 974d00​: OUTPUT«1 1 1 1␤===SORRY!===␤Element
shifted from empty list␤»
<grondilu> m​: for ^2 { my @​b = 1 xx 4; my @​c = (@​b.shift xx 2) xx 2; }
<camelia> rakudo-moar 974d00​: OUTPUT«===SORRY!===␤Element shifted from
empty list␤»
<grondilu> or affects it.
<masak> interesting.
<masak> my bet​: something gets the wrong OUTER somewhere when two
nested infix​:<xx> are used like that.
<masak> the wrong OUTER points back to the @​b from the first
iteration, and so tries to shift an empty array.
<masak> that doesn't explain why we need to observe it for it to
happen, but it explains everything else.

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From @smls

It works fine now​:

  ➜ for ^2 { my @​b = 1 xx 4; say (@​b.shift xx 2) xx 2 }
  ((1 1) (1 1))
  ((1 1) (1 1))

Was apparently fixed a year ago​:

  https://gist.github.com/Whateverable/e2a6fe61150eb2595ac0ff6929daeab1
  rakudo/rakudo@5e61516

Can be closed with tests.

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Oct 7, 2017

From @moritz

Tested in Raku/roast@afa1f74636

@p6rt
Copy link
Author

p6rt commented Oct 7, 2017

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

@p6rt p6rt closed this as completed Oct 7, 2017
@p6rt p6rt added the testneeded label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant