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

.push allows freaky action-at-a-distance in Rakudo #1340

Closed
p6rt opened this issue Oct 3, 2009 · 8 comments
Closed

.push allows freaky action-at-a-distance in Rakudo #1340

p6rt opened this issue Oct 3, 2009 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 3, 2009

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

Searchable as RT69548$

@p6rt
Copy link
Author

p6rt commented Oct 3, 2009

From @masak

I'm pretty sure I've seen this bug report before, but I can't find it,
so reporting it just in case.

<masak> rakudo​: my $x = 1; my @​a; while $x < 5 { @​a.push($x); $x++ };
say @​a.perl
<p6eval> rakudo e976f2​: OUTPUT«[5, 5, 5, 5]␤»

Expected​: [1, 2, 3, 4].

@p6rt
Copy link
Author

p6rt commented Oct 4, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S32-array/push.t

commit 41a786ddea8e7eddeed7a8bf58340d2d62babd1b
Author​: Kodi <Kodi@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Sun Oct 4 20​:57​:41 2009 +0000

  [t/spec/S32-array/push.t] Added a test for RT #​69548
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;28608 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --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

@p6rt
Copy link
Author

p6rt commented Oct 4, 2009

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

@p6rt
Copy link
Author

p6rt commented Oct 18, 2009

From @pmichaud

Bug for .push now fixed in 827734a. I suspect there's a similar
problem with .unshift, but trying the same approach for .unshift that I
used for .push causes a build failure which I've been unable to track down.

We can either open a new ticket for .unshift, or leave this ticket open
until unshift is fixed here. We probably need similar tests for
.unshift as we had above for .push.

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Aug 2, 2010

From @bbkr

$ perl6 -e 'my $x = 1; my @​a; while $x < 5 { @​a.push($x); $x++ }; say ~@​a'
1 2 3 4
$ perl6 -e 'my $x = 1; my @​a; while $x < 5 { @​a.unshift($x); $x++ }; say
~@​a'
4 3 2 1

taken for tests

@p6rt
Copy link
Author

p6rt commented Aug 2, 2010

From @bbkr

uncommented test in t/spec/S32-array/push.t
added test in t/spec/S32-array/unshift.t

@p6rt
Copy link
Author

p6rt commented Aug 2, 2010

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

@p6rt p6rt closed this as completed Aug 2, 2010
@p6rt
Copy link
Author

p6rt commented Aug 2, 2010

From @kyleha

This 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
Author​: bbkr <bbkr@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Mon Aug 2 10​:20​:34 2010 +0000

  [t/spec] tests for RT #​69548 .push allows freaky action-at-a-distance in Rakudo
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31887 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --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

@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