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

is rw/copy traits causes assignment/binding confusion #579

Closed
p6rt opened this issue Jan 5, 2009 · 6 comments
Closed

is rw/copy traits causes assignment/binding confusion #579

p6rt opened this issue Jan 5, 2009 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jan 5, 2009

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

Searchable as RT61982$

@p6rt
Copy link
Author

p6rt commented Jan 5, 2009

From @moritz

Rakudo r34428

sub example ($x is rw) {
  $x = 3;
  my @​a;
  @​a.push($x);
  $x = 5;
  say @​a[0];
}
example(3);

Output is 5, should be 3.
The problem is the same for s/is rw/is copy/

A test for the "is copy" version is in
t/spec/integration/99problems-31-to-40.t

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Jan 20, 2009

From @moritz

On Mon Jan 05 10​:24​:13 2009, moritz wrote​:

Rakudo r34428

sub example ($x is rw) {
$x = 3;
my @​a;
@​a.push($x);
$x = 5;
say @​a[0];
}
example(3);

Output is 5, should be 3.
The problem is the same for s/is rw/is copy/

A test for the "is copy" version is in
t/spec/integration/99problems-31-to-40.t

Actually the regression on t/spec/integration/man-or-boy.t which came
with the rvar2 branch merge also is a manifestation of an 'is copy' bug​:

my @​results = 1, 0, -2, 0, 1, 0, 1, -1, -10, -30;
sub A($k is copy, &x1, &x2, &x3, &x4, &x5) {
  my $B;
  $B = sub { A(--$k, $B, &x1, &x2, &x3, &x4) };
  if ($k <= 0) {
  return x4($k, &x1, &x2, &x3, &x4, &x5)
  + x5($k, &x1, &x2, &x3, &x4, &x5);
  }
  return $B();
};
for 0 .. (@​results-1) -> $i {
  A($i, sub {1}, sub {-1}, sub {-1}, sub {1}, sub {0});
  say $i;
}

Output​:
0
0
0
0
-1
-2
-2
-3
-5
-6

The $i in the loop is modified by the call to A(), which shouldn't happen.

@p6rt
Copy link
Author

p6rt commented Jan 20, 2009

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

@p6rt
Copy link
Author

p6rt commented Jun 30, 2010

From @bbkr

New issue here​: example(3) seems now to be illegal

[13​:07] <bbkr> rakudo​: sub example ($x is rw) { $x = 3; my @​a;
@​a.push($x); $x = 5; say @​a[0]; }; example(3);
[13​:07] <p6eval> rakudo 261eb2​: OUTPUT«Cannot assign to readonly value␤
in '&infix​:<=>' at line 1␤ in 'example' at line 11​:/tmp/Px0mu1JHtu␤
in main program body at line 11​:/tmp/Px0mu1JHtu␤»
[13​:07] <bbkr> where is raadonly value here?
[13​:08] <bbkr> readonly*
[13​:09] <masak> bbkr​: ah. it's the 3.
[13​:10] <masak> bbkr​: the 3 is a literal, hence read-only.

However it works as expected when passing non-literal param​:

[13​:11] <bbkr> rakudo​: sub example ($x is rw) { $x = 3; my @​a;
@​a.push($x); $x = 5; say @​a[0]; }; my $z = 3; example($z);
[13​:11] <p6eval> rakudo 261eb2​: OUTPUT«3␤»

@p6rt
Copy link
Author

p6rt commented Jul 5, 2010

From @moritz

The 'man or boy' tests now pass again, I consider this sufficient test
coverage to close the ticket.

@p6rt
Copy link
Author

p6rt commented Jul 5, 2010

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

@p6rt p6rt closed this as completed Jul 5, 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