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

chained array item assignment leaves one item undefined #2292

Closed
p6rt opened this issue Dec 12, 2010 · 7 comments
Closed

chained array item assignment leaves one item undefined #2292

p6rt opened this issue Dec 12, 2010 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 12, 2010

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

Searchable as RT80614$

@p6rt
Copy link
Author

p6rt commented Dec 12, 2010

From @moritz

12​:05 < moritz_> rakudo​: my @​a = 1, 2, 3; my @​b; my $c = @​b[0] = @​a[1];
say $c; say @​b[0];
12​:05 <+p6eval> rakudo : OUTPUT«2␤Any()␤»

both should be 2

12​:04 < moritz_> rakudo​: my @​b; my $c = @​b[0] = 1; say $c; say @​b[0];
12​:04 <+p6eval> rakudo : OUTPUT«1␤1␤»

... and it works fine if the right-most term is not an array item, but
rather a scalar.

Found while pursuing masak's coding contest, problem 5.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Dec 23, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in S03-operators/assign.t

commit 1e438c8bafa5b88fce0181dc64484a423b2ca433
Author​: Kyle Hasselbacher <kyleha@​gmail.com>
Date​: Thu Dec 23 16​:01​:53 2010 -0600

  [assign] Test for RT 80614​: chained array item assignment

Inline Patch
diff --git a/S03-operators/assign.t b/S03-operators/assign.t
index 0386e26..53e30c1 100644
--- a/S03-operators/assign.t
+++ b/S03-operators/assign.t
@@ -6,7 +6,7 @@ use Test;
 #                      V
 # L<S03/Changes to Perl 5 operators/list assignment operator now parses on the right>
 
-plan 242;
+plan 244;
 
 
 # tests various assignment styles
@@ -764,4 +764,15 @@ sub l () { 1, 2 };
     is $x, 5, '... with correct result';
 }
 
+# RT #80614
+{
+   my @a = 1,2,3;
+   my @b;
+   my $rt80614 = @b[0] = @a[1];
+
+   is $rt80614, 2, 'assignment to scalar via array item from array item';
+   #?rakudo todo 'RT 80614'
+   is @b[0], 2, 'assignment to array item from array item to scalar';
+}
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Dec 23, 2010

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

@p6rt
Copy link
Author

p6rt commented Feb 26, 2014

From @coke

On Sun Dec 12 03​:09​:07 2010, moritz wrote​:

12​:05 < moritz_> rakudo​: my @​a = 1, 2, 3; my @​b; my $c = @​b[0] = @​a[1];
say $c; say @​b[0];
12​:05 <+p6eval> rakudo : OUTPUT«2␤Any()␤»

both should be 2

12​:04 < moritz_> rakudo​: my @​b; my $c = @​b[0] = 1; say $c; say @​b[0];
12​:04 <+p6eval> rakudo : OUTPUT«1␤1␤»

... and it works fine if the right-most term is not an array item, but
rather a scalar.

Found while pursuing masak's coding contest, problem 5.

Cheers,
Moritz

A test for this was added to S03-operators/assign.t - 2 tests in a block - one passes, one fails (and is todo'd) - but if you run that test directly (hoisting it out into its own file), it passes. very odd.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 13, 2014

From @usev6

I tried to golf this (chained assignment and test failure) a bit and found the following​:

$ perl6-m -e 'my $x; $x = 1; my @​a; my $y = @​a[0] = 2; say @​a[0]'
2
$ perl6-m -e 'my $x; ($x) = 1; my @​a; my $y = @​a[0] = 2; say @​a[0]'
(Any)

The following looks weird as well​:

$ perl6-m -e 'my $y; my @​a = (); $y = @​a[0] = 2; say @​a[0]'
2
$ perl6-m -e 'my $y; my @​a; @​a = (); $y = @​a[0] = 2; say @​a[0]'
(Any)

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 13, 2014

From @usev6

I tried to golf this (chained assignment and test failure) a bit and found the following​:

$ perl6-m -e 'my $x; $x = 1; my @​a; my $y = @​a[0] = 2; say @​a[0]'
2
$ perl6-m -e 'my $x; ($x) = 1; my @​a; my $y = @​a[0] = 2; say @​a[0]'
(Any)

The following looks weird as well​:

$ perl6-m -e 'my $y; my @​a = (); $y = @​a[0] = 2; say @​a[0]'
2
$ perl6-m -e 'my $y; my @​a; @​a = (); $y = @​a[0] = 2; say @​a[0]'
(Any)

@p6rt p6rt closed this as completed Jun 17, 2015
@p6rt
Copy link
Author

p6rt commented Jun 17, 2015

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

@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