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

Double layers of array when binding an Array in a scalar variable to an 'is copy' array variable in Rakudo #1896

Closed
p6rt opened this issue Jun 28, 2010 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 28, 2010

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

Searchable as RT76242$

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @masak

<masak> rakudo​: my $a = [1, 2, 3]; foo($a); bar($a); sub foo(@​a) { say
@​a.perl }; sub bar(@​a is copy) { say @​a.perl }
<p6eval> rakudo 05684c​: OUTPUT«[1, 2, 3]␤[[1, 2, 3]]␤»
<masak> that one's new, isn't it?
* masak submits rakudobug
<pmichaud> masak​: that one is interesting. I'm not sure it's a bug.
<mathw> pmichaud​: it is quite surprising...
<masak> pmichaud​: oh, come on! :/
<mathw> although I suspect flattening would hide it in many cases
<pmichaud> my $a = [1,2,3]; my @​b = $a; say @​b.perl;
<masak> pmichaud​: er. put differently, where does the spec say
"putting 'is copy' on an array gives you an extra layer of array"?
<moritz_> rakudo​: sub bar(@​a is copy) { say @​a.perl }; say bar [1, 2, 3]
<p6eval> rakudo 05684c​: OUTPUT«[[1, 2, 3]]␤1␤»
<moritz_> pmichaud​: that's assignment
<moritz_> pmichaud​: signature binding is *binding*
<pmichaud> moritz_​: except for is_copy
<pmichaud> it's the same logic by which
<pmichaud> my $b = [1,2,3]; sub xyz($x is copy) { $x[1] = 'b'; };
xyz($b); say $b.perl;
<pmichaud> rakudo​: my $b = [1,2,3]; sub xyz($x is copy) { $x[1] =
'b'; }; xyz($b); say $b.perl;
<p6eval> rakudo 05684c​: OUTPUT«[1, "b", 3]␤»
<pmichaud> anyway, I can fix it.
<pmichaud> I agree that the other interpretation likely makes more sense.
<masak> rakudo​: my $a = 5; sub bar(@​a is copy) { say @​a.perl }; bar($a)
<p6eval> rakudo 05684c​: OUTPUT«Nominal type check failed for parameter
'@​a'; expected Positional but got Int instead␤ in 'bar' [...]
<masak> pmichaud​: if the above doesn't bind, why does my first line
give double arrays?
<masak> seems very arbitrary.
<pmichaud> I just said I wasn't certain of it. :-)
<masak> just trying to make you even less certain :P
<pmichaud> the "is copy" logic is still not completely nailed down,
based on discussion with TimToady++ at yapc​::na
<masak> I do see the parallel with attr arrays and :attr[]. by the way.
<pmichaud> anyway, the one thing I *am* certain of is that "is copy"
is not "binding". Indeed, the whole point of "is copy" is to avoid the
bind. :-)
<mathw> yes that's what I thought :)
<moritz_> I thought it copied, and then binds
<pmichaud> okay, one can think of it that way. :-)
<pmichaud> but it's not binding to the argument
<pmichaud> in the same way, my @​b = $a; is a bind only in the sense
that we bind he symbol '@​b' to an array before doing the assign
<pmichaud> anyway, I know the fix. Should be one-line :)
<pmichaud> did the ticket get filed yet?

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @pmichaud

Now fixed in c18d372. Assigning to moritz++ for spectest coverage.

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

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

@p6rt
Copy link
Author

p6rt commented Jun 29, 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/S05-match/make.t, t/spec/S06-traits/is-copy.t

commit b1a01252fa1459396c9f771a5c47c335eb5e6383
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Tue Jun 29 23​:14​:20 2010 +0000

  [t/spec] test for RT #​76242, "is copy" array parameters
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31508 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S05-match/make.t b/t/spec/S05-match/make.t
index 1a4390b..c0cda39 100644
--- a/t/spec/S05-match/make.t
+++ b/t/spec/S05-match/make.t
@@ -7,7 +7,8 @@ plan 5;
 # L<S05/Bracket rationalization/reduction using the>
 
 "4" ~~ / (\d) { make $0.sqrt } Remainder /;
-nok($/);
+nok($/, 'No match');
+#?rakudo todo '.ast of failed match (questionable)'
 is($/.ast , 2);
 
 # L<S05/Match objects/"Fortunately, when you just want to return a different">
@@ -15,7 +16,8 @@ is($/.ast , 2);
 "blah foo blah" ~~ / foo                 # Match 'foo'
                       { make 'bar' }     # But pretend we matched 'bar'
                     /;
-ok($/);
+ok($/, 'matched');
+#?rakudo todo '$()'
 is($(), 'bar');
 is $/.ast, 'bar', '$/.ast';
 
diff --git a/t/spec/S06-traits/is-copy.t b/t/spec/S06-traits/is-copy.t
index ec6c84c..ae634e8 100644
--- a/t/spec/S06-traits/is-copy.t
+++ b/t/spec/S06-traits/is-copy.t
@@ -4,7 +4,7 @@ use Test;
 # L<S06/"Parameter traits"/"=item is copy">
 # should be moved with other subroutine tests?
 
-plan 16;
+plan 17;
 
 {
   sub foo($a is copy) {
@@ -61,4 +61,16 @@ plan 16;
     is(%test<x>, 1,    '...and original is unmodified.');
 }
 
+# RT #76242
+{
+    sub t(@a is copy) {
+        my $x = 0;
+        $x++ for @a;
+        $x;
+    }
+
+    my $a = [1, 2, 3];
+    is t($a), 3, 'passing [1,2,3] to @a is copy does results in three array items';
+}
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Jun 30, 2010

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

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