E4060#
方法类型不匹配。
我们要求实现的方法类型必须与特征(trait)中定义的类型完全一致。注意,以下情况的类型不被视为相同:
标记参数顺序不同:如
(a~ : Int, b~ : Int) -> Unit
和(b~ : Int, a~ : Int) -> Unit
。可选参数不同:如
(a : Int, b? : Int) -> Unit
和(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)
}
建议#
请确保方法类型与特征(trait)中定义的类型匹配。
impl A for T with f(self : T) -> Int {
ignore(self)
}