E4060#
Method type mismatch.
We require the type of implementation to have the exactly the same type as the one defined in the trait. Notably, the following types are not considered the same.
Labelled arguments with different order:
(a~ : Int, b~ : Int) -> Unit
and(b~ : Int, a~ : Int) -> Unit
.Optional arguments:
(a : Int, b? : Int) -> Unit
and(a : Int) -> Unit
.
错误示例#
trait A {
f(Self) -> Int
}
type T Int
impl A for T with f(self : T) -> Int {
// ^
// Error: Method f of trait A is expected to have type (T) -> Int,
// it cannot be implemented with type (T) -> Unit
ignore(self)
}
建议#
Make sure the method type matches the trait method type.
impl A for T with f(self : T) -> Int {
ignore(self)
}