在 Raku 中,无法从同一文件中定义的 class 继承方法特征

Can't inherit, in Raku, a method trait from a class defined in the same file

用 trait_mod 定义的方法特征完美地继承自另一个文件中定义的 class。 当两个 class 定义在同一个文件中时,这似乎不起作用。

以下 2 个文件可以很好地协同工作:

# mmm.pm6

class TTT is export  {

    multi trait_mod:<is> (Routine $meth, :$something! ) is export
    {
        say "METH : ", $meth.name;
    }
}
# aaa.p6

use lib <.>;
use mmm;

class BBB is TTT {
    method work is something {  }
}

输出为:METH : work

但是收集在以下唯一文件中的相同代码给出了错误消息

# bbb.p6

class TTT is export  {

    multi trait_mod:<is> (Routine $meth, :$something! ) is export
    {
        say "METH : ", $meth.name;
    }
}

class BBB is TTT {
    method work is something {  }
}

输出为:

===SORRY!=== Error while compiling /home/home.mg6/yves/ygsrc/trait/bbb.p6
Can't use unknown trait 'is' -> 'something' in a method declaration.
at /home/home.mg6/yves/ygsrc/trait/bbb.p6:12
    expecting any of:
        rw raw hidden-from-backtrace hidden-from-USAGE pure default
        DEPRECATED inlinable nodal prec equiv tighter looser assoc
        leading_docs trailing_docs

我运行正在使用这个 Rakudo 版本:

This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03
implementing Perl 6.d.

为什么我不能 运行 来自单个文件的代码? 我错过了什么?

根据 documentation:

Module contents (classes, subroutines, variables, etc.) can be exported from a module with the is export trait; these are available in the caller's namespace once the module has been imported with import or use.

您可以尝试使用 importis trait 导入当前包:

bbb.p6:

module X {  # <- declare a module name, e.g. 'X' so we can import it later..
    class TTT is export  {
        multi trait_mod:<is> (Routine $meth, :$something! ) is export
        {
            say "METH : ", $meth.name;
        }
    }
}

import X;
class BBB is TTT {
    method work is something {  }
}