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

state variable declared inside of a {} interpolation in a string, attaches to wrong scope #5622

Closed
p6rt opened this issue Aug 28, 2016 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Aug 28, 2016

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

Searchable as RT129114$

@p6rt
Copy link
Author

p6rt commented Aug 28, 2016

From @smls

This is how a state variable normally works​:

  ➜ for ^2 { for ^2 { say (state $a)++ } }
  0
  1
  0
  1

But when it is declared inside a {} interpolation in a string, it misbehaves​:

  ➜ for ^2 { for ^2 { say "{ (state $a)++ }" } }
  0
  1
  2
  3

It's as if the state variable attaches to the scope of the outer loop or mainline, instead of the inner loop like it should.

@p6rt
Copy link
Author

p6rt commented Feb 6, 2018

From @dogbert17

On Sun, 28 Aug 2016 02​:56​:47 -0700, smls75@​gmail.com wrote​:

This is how a state variable normally works​:

➜ for ^2 { for ^2 { say (state $a)++ } }
0
1
0
1

But when it is declared inside a {} interpolation in a string, it
misbehaves​:

➜ for ^2 { for ^2 { say "{ (state $a)++ }" } }
0
1
2
3

It's as if the state variable attaches to the scope of the outer loop
or mainline, instead of the inner loop like it should.

Looks as if the code behaves as expected according to jnthn. See
https://irclog.perlgeek.de/perl6-dev/2018-02-06#i_15783359

Rejecting issue.

@p6rt
Copy link
Author

p6rt commented Feb 6, 2018

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

@p6rt
Copy link
Author

p6rt commented Feb 6, 2018

@dogbert17 - Status changed from 'open' to 'rejected'

@p6rt
Copy link
Author

p6rt commented Feb 6, 2018

From @AlexDaniel

Just to clarify, the last snippet now produces 0 0 0 0, which is indeed correct.

There are tests for this change in general, but possibly not for that particular case. Can we get it covered just in case?

「testneeded」

On 2018-02-06 05​:51​:23, jan-olof.hendig@​bredband.net wrote​:

On Sun, 28 Aug 2016 02​:56​:47 -0700, smls75@​gmail.com wrote​:

This is how a state variable normally works​:

➜ for ^2 { for ^2 { say (state $a)++ } }
0
1
0
1

But when it is declared inside a {} interpolation in a string, it
misbehaves​:

➜ for ^2 { for ^2 { say "{ (state $a)++ }" } }
0
1
2
3

It's as if the state variable attaches to the scope of the outer loop
or mainline, instead of the inner loop like it should.

Looks as if the code behaves as expected according to jnthn. See
https://irclog.perlgeek.de/perl6-dev/2018-02-06#i_15783359

Rejecting issue.

@p6rt
Copy link
Author

p6rt commented Feb 6, 2018

@AlexDaniel - Status changed from 'rejected' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 6, 2018

From @zoffixznet

Tests​: Raku/roast@0552e64c1f

@p6rt
Copy link
Author

p6rt commented Feb 6, 2018

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

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