E4056#
Compiler diagnostic name: method_duplicate.
方法已被定义。一个类型不能为同一个接收者定义两个同名方法,否则方法调用将无法解析到唯一的方法体。
错误示例#
///|
struct Point {
x : Int
y : Int
}
///|
fn Point::to_string(self : Point) -> String {
"(" + self.x.to_string() + "," + self.y.to_string() + ")"
}
///|
fn Point::to_string(self : Point) -> String {
"<" + self.x.to_string() + "," + self.y.to_string() + ">"
}
建议#
请删除重复的方法,只保留一个:
///|
priv struct Point {
x : Int
y : Int
}
///|
fn Point::to_string(self : Point) -> String {
"(" + self.x.to_string() + "," + self.y.to_string() + ")"
}
///|
test {
let point : Point = { x: 1, y: 2 }
inspect(point.to_string(), content="(1,2)")
}