E4145#
Cannot implement trait because it is sealed.
Sealed trait means the trait is not allowed to be implemented in other packages.
Use pub(open)
to make the trait open to be implemented by other packages.
错误示例#
Suppose there is a package a
in module username/hello
:
a/moon.pkg.json
:
{}
a/a.mbt
:
pub trait Sealed {
to_int() -> Int
}
While in package b
:
b/moon.pkg.json
:
{
"import": [
"username/hello/a"
]
}
b/b.mbt
:
type A Int
impl @a.Sealed for A with to_int(self : A) -> Int { // Error: Cannot implement trait '@a.Sealed' because it is readonly.
self._
}
建议#
You can change the visibility of the trait to pub(open)
, so that it can be
implemented by other packages.
pub(open) trait Sealed {
to_int() -> Int
}