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

Problem when directly assigning object attributes for self.new #308

Closed
p6rt opened this issue Sep 13, 2008 · 5 comments
Closed

Problem when directly assigning object attributes for self.new #308

p6rt opened this issue Sep 13, 2008 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 13, 2008

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

Searchable as RT58818$

@p6rt
Copy link
Author

p6rt commented Sep 13, 2008

From @cjfields

When attempting to set up a simple clone method (awaiting .clone to be
implemented), I noticed an odd issue where passing attributes directly
to new() using self.attribute winds up binding to the original
object's attribute. However, using a temp variable works fine.
Notably, the problem disappears if the attribute in question is typed
('has Int $.a is rw;' fixes it).

class Foo {
  has $.a is rw;
  has $.b is rw;
  method clone_Foo {
  my $newval = self.b;
  return self.new(a => self.a, b => $newval);
  }
};

my $first = Foo.new(a => 1, b => 2);
say $first.a; # 1
say $first.b; # 2

my $second = $first.clone_Foo;
say $second.a; # 1
say $second.b; # 2

$second.a = 4;
$second.b = 8;

say $second.a; # 4
say $second.b; # 8
say $first.a; # should be 1, is 4
say $first.b; # 2 (correct)

chris

@p6rt
Copy link
Author

p6rt commented Nov 19, 2008

From @moritz

On Fri Sep 12 22​:07​:52 2008, cjfields@​illinois.edu wrote​:

When attempting to set up a simple clone method (awaiting .clone to be
implemented), I noticed an odd issue where passing attributes directly
to new() using self.attribute winds up binding to the original
object's attribute. However, using a temp variable works fine.
Notably, the problem disappears if the attribute in question is typed
('has Int $.a is rw;' fixes it).

I've re-formulated your script as a test file (using Test.pm) and added
it the test suite in (pugs) r23045, and to 'make spectest' in (parrot)
32905.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Nov 19, 2008

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

@p6rt
Copy link
Author

p6rt commented Jan 20, 2009

From @moritz

On Wed Nov 19 14​:39​:14 2008, moritz wrote​:

On Fri Sep 12 22​:07​:52 2008, cjfields@​illinois.edu wrote​:

When attempting to set up a simple clone method (awaiting .clone to be
implemented), I noticed an odd issue where passing attributes directly
to new() using self.attribute winds up binding to the original
object's attribute. However, using a temp variable works fine.
Notably, the problem disappears if the attribute in question is typed
('has Int $.a is rw;' fixes it).

I've re-formulated your script as a test file (using Test.pm) and added
it the test suite in (pugs) r23045, and to 'make spectest' in (parrot)
32905.

These tests now all parse, so closing ticket.

Thanks for the report,
Moritz

@p6rt
Copy link
Author

p6rt commented Jan 20, 2009

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

@p6rt p6rt closed this as completed Jan 20, 2009
@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