class A {
has $.n;
# If this method is uncommented then the clone won't be sunk
# method clone {
# my $clone = callwith(|%_);
# return $clone;
# }
method sink(-->Nil) { say "sinking...$!n" }
}
sub ccc(A:D $a) { $a.clone(n=>2) }
ccc(A.new(n=>1));
say 'Done';
Above prints:
sinking...2
Done
However, if the custom clone
method is used, then the returned clone from ccc
won't be sunk for some reason. It works if I sink
it explicitly at call site or if I change the my $clone = callwith(|%_)
line to my $clone := callwith(|%_)
. Is this expected? What's the reason that it's working this way?
Thanks!