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
.push allows freaky action-at-a-distance in Rakudo #1340
Comments
From @masakI'm pretty sure I've seen this bug report before, but I can't find it, <masak> rakudo: my $x = 1; my @a; while $x < 5 { @a.push($x); $x++ }; Expected: [1, 2, 3, 4]. |
From @kylehaThis is an automatically generated mail to inform you that tests are now available in t/spec/S32-array/push.t commit 41a786ddea8e7eddeed7a8bf58340d2d62babd1b [t/spec/S32-array/push.t] Added a test for RT #69548 Inline Patchdiff --git a/t/spec/S32-array/push.t b/t/spec/S32-array/push.t
index fd6005d..bce61af 100644
--- a/t/spec/S32-array/push.t
+++ b/t/spec/S32-array/push.t
@@ -9,7 +9,7 @@ Push tests
=end description
-plan 50;
+plan 52;
# basic push tests
{
@@ -26,17 +26,17 @@ plan 50;
is(@push[1], 2, 'we found the right element');
push(@push, 3);
- is(+@push, 3, 'we have 3 element in the array');
+ is(+@push, 3, 'we have 3 elements in the array');
is(@push[2], 3, 'we found the right element');
push(@push, 4);
- is(+@push, 4, 'we have 4 element in the array');
+ is(+@push, 4, 'we have 4 elements in the array');
is(@push[3], 4, 'we found the right element');
#?rakudo skip 'named args'
{
push(:array(@push), 5);
- is(+@push, 5, 'we have 5 element in the array (with named arg)');
+ is(+@push, 5, 'we have 5 elements in the array (with named arg)');
is(@push[4], 5, 'we found the right element (with named arg)');
}
}
@@ -151,4 +151,25 @@ plan 50;
is(@push[0][*-1], 25, 'nested arrayref, last value is 25');
}
+# RT #69548
+{
+ {
+ my $x = 1;
+ my @a;
+ push @a, $x;
+ ++$x;
+
+ is @a[0], 1, 'New element created by push(@a, $x) isn\'t affected by changes to $x';
+ }
+ {
+ my $x = 1;
+ my @a;
+ push @a, $x;
+ ++@a[0];
+
+ is $x, 1, '$x isn\'t affected by changes to new element created by push(@a, $x)';
+ }
+}
+
+
# vim: syn=perl6 |
The RT System itself - Status changed from 'new' to 'open' |
From @pmichaudBug for .push now fixed in 827734a. I suspect there's a similar We can either open a new ticket for .unshift, or leave this ticket open Thanks! Pm |
From @bbkr$ perl6 -e 'my $x = 1; my @a; while $x < 5 { @a.push($x); $x++ }; say ~@a' taken for tests |
From @bbkruncommented test in t/spec/S32-array/push.t |
@bbkr - Status changed from 'open' to 'resolved' |
From @kylehaThis is an automatically generated mail to inform you that tests are now available in at least one of these files: t/spec/S32-array/push.t, t/spec/S32-array/unshift.t commit d1d53c0423c9ed041a5ee7ad691bed61d655a494 [t/spec] tests for RT #69548 .push allows freaky action-at-a-distance in Rakudo Inline Patchdiff --git a/t/spec/S32-array/push.t b/t/spec/S32-array/push.t
index d2dd721..c0c7a6b 100644
--- a/t/spec/S32-array/push.t
+++ b/t/spec/S32-array/push.t
@@ -9,7 +9,7 @@ Push tests
=end description
-plan 50;
+plan 51;
# basic push tests
{
@@ -157,17 +157,17 @@ plan 50;
my @a = ();
push @a, $x;
++$x;
-
+
is @a[0], 1, 'New element created by push(@a, $x) isn\'t affected by changes to $x';
}
- # {
- # my $x = 1;
- # my @a = ();
- # push @a, $x;
- # ++@a[0];
- #
- # is $x, 1, '$x isn\'t affected by changes to new element created by push(@a, $x)';
- # }
+ {
+ my $x = 1;
+ my @a = ();
+ push @a, $x;
+ ++@a[0];
+
+ is $x, 1, '$x isn\'t affected by changes to new element created by push(@a, $x)';
+ }
}
diff --git a/t/spec/S32-array/unshift.t b/t/spec/S32-array/unshift.t
index b126e19..cf989c2 100644
--- a/t/spec/S32-array/unshift.t
+++ b/t/spec/S32-array/unshift.t
@@ -9,7 +9,7 @@ Unshift tests
=end description
-plan 59;
+plan 61;
# basic unshift tests
@@ -145,4 +145,25 @@ plan 59;
# # best not to uncomment this it just go on forever
# todo_throws_ok { 'unshift @unshift, 10' }, '?? what should this error message be ??', 'cannot unshift onto a Inf array';
# }
+
+# RT #69548
+{
+ {
+ my $x = 1;
+ my @a = ();
+ unshift @a, $x;
+ ++$x;
+
+ is @a[0], 1, 'New element created by unshift(@a, $x) isn\'t affected by changes to $x';
+ }
+ {
+ my $x = 1;
+ my @a = ();
+ unshift @a, $x;
+ ++@a[0];
+
+ is $x, 1, '$x isn\'t affected by changes to new element created by unshift(@a, $x)';
+ }
+}
+
# vim: ft=perl6 |
Migrated from rt.perl.org#69548 (status was 'resolved')
Searchable as RT69548$
The text was updated successfully, but these errors were encountered: