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

Fix .clone() when providing new array/hash attributes #170

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/core/Mu.pm
Expand Up @@ -436,7 +436,20 @@ my class Mu {
}
my $acc_name := $name.substr(2);
if $attr.has-accessor && %twiddles.exists($acc_name) {
nqp::getattr($cloned, $package, $name) = %twiddles{$acc_name};
sub is_kind($sigil) {
nqp::index($sigil, nqp::substr($name, 0, 1)) >= 0
}
# we don't want to update the original hash/array because a new one was supplied,
# create a new one to hold the value and bind the attribute
if is_kind('@') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should } elsif ($name ~~ Array) {, methinks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ~~ Positional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work because $name is not a positional or hash... it is the name of the attribute. Therefore, we never fall into this branch, and values are not coerced correctly.

my @list_value = %twiddles{$acc_name};
nqp::bindattr($cloned, $package, $name, @list_value);
} elsif is_kind('%') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should } elsif ($name ~~ Hash) {, methinks

my %hash_value = %twiddles{$acc_name};
nqp::bindattr($cloned, $package, $name, %hash_value);
} else {
nqp::bindattr($cloned, $package, $name, %twiddles{$acc_name});
}
}
}
$cloned
Expand Down