【发布时间】:2020-08-20 05:55:51
【问题描述】:
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';
上图:
sinking...2
Done
但是,如果使用自定义的clone 方法,则从ccc 返回的克隆不会由于某种原因而沉没。如果我在呼叫站点明确地sink 它或者如果我将my $clone = callwith(|%_) 行更改为my $clone := callwith(|%_),它就可以工作。这是预期的吗?为什么会这样?
谢谢!
【问题讨论】: