E4056#
Compiler diagnostic name: method_duplicate.
Method has already been defined. A type cannot define two methods with the same name and receiver because a method call would have no single body to resolve to.
Erroneous example#
///|
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() + ">"
}
Suggestion#
Remove the duplicate method and keep only one method:
///|
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)")
}