Navigation Menu

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

non-modifier form of 'if' within 'for' loop fails, while the modifier form works #1883

Closed
p6rt opened this issue Jun 27, 2010 · 6 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 27, 2010

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

Searchable as RT76174$

@p6rt
Copy link
Author

p6rt commented Jun 27, 2010

From pk-rakudo@kailasa.net

perl6 -v
This compiler is built with the Parrot Compiler Toolkit, parrot revision 46946.

# this works as expected

perl6 -e 'my @​a = 0, 1, 2; for @​a {$_++ if $_}; say @​a.perl'
[0, 2, 3]

# this fails

perl6 -e 'my @​a = 0, 1, 2; for @​a { if $_ { $_++ } }; say @​a.perl'
[0, 1, 2]

Thanks,
Prakash Kailasa

@p6rt
Copy link
Author

p6rt commented Jun 27, 2010

From @pmichaud

On Sun Jun 27 14​:16​:46 2010, pkailasa wrote​:

# this fails

perl6 -e 'my @​a = 0, 1, 2; for @​a { if $_ { $_++ } }; say @​a.perl'
[0, 1, 2]

It now works in current Rakudo​:

  pmichaud@​plum​:~/rakudo$ cat x
  my @​a = 0, 1, 2;
  for @​a { if $_ { $_++ } };
  say @​a.perl;
  pmichaud@​plum​:~/rakudo$ ./perl6 x
  [0, 2, 3]

Assigning to moritz for spectest coverage.

Pm

@p6rt
Copy link
Author

p6rt commented Jun 27, 2010

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

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S04-statements/if.t

commit 7dae39e04f140333b2a794ec70a4f72d4cced480
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Mon Jun 28 20​:58​:57 2010 +0000

  [t/spec] test for RT #​76174, "if" does not break lexical aliasing of $_ in a for-loop
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31485 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S04-statements/if.t b/t/spec/S04-statements/if.t
index 561a1ca..946d3d5 100644
--- a/t/spec/S04-statements/if.t
+++ b/t/spec/S04-statements/if.t
@@ -11,7 +11,7 @@ Basic "if" tests.
 
 # L<S04/Conditional statements>
 
-plan 25;
+plan 26;
 
 my $x = 'test';
 if ($x eq $x) { pass('if ($x eq $x) {} works'); } else { flunk('if ($x eq $x) {} failed'); }
@@ -156,4 +156,12 @@ if (Mu) { flunk('if (Mu) {} failed'); } else { pass('if (Mu) {} works'); }
 # L<S04/Statement parsing/keywords require whitespace>
 eval_dies_ok('if($x > 1) {}','keyword needs at least one whitespace after it');
 
+# RT #76174
+# scoping of $_ in 'if' shouldn't break aliasing
+{
+    my @a = 0, 1, 2;
+    for @a { if $_ { $_++ } };
+    is ~@a, '0 2 3', '"if" does not break lexical aliasing of $_'
+}
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @moritz

Test coverage ensured, closing ticket.

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

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

@p6rt p6rt closed this as completed Jun 28, 2010
@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