E4005

E4005#

This error occurs when a trait has multiple declarations of the same method name. Each method in a trait must have a unique name to avoid ambiguity.

Erroneous example#

///|
trait Animal {
  make_sound(Self) -> String
  make_sound(Self) -> String // Error: method make_sound is declared twice
}

Suggestion#

Remove the duplicate method declaration and keep only one definition for each method name:

///|
priv trait Animal {
  make_sound(Self) -> String // Only declare the method once
}

///|
priv struct Dog {}

///|
impl Animal for Dog with make_sound(_) {
  "woof"
}

///|
fn[T : Animal] describe(animal : T) -> String {
  animal.make_sound()
}

///|
test {
  let dog = Dog::{  }
  inspect(describe(dog), content="woof")
}

If you need different method behaviors, use distinct method names:

///|
priv trait LoudAnimal {
  make_sound(Self) -> String
  make_loud_sound(Self) -> String // Use a different name for different behavior
}

///|
priv struct Cat {}

///|
impl LoudAnimal for Cat with make_sound(_) {
  "meow"
}

///|
impl LoudAnimal for Cat with make_loud_sound(_) {
  "MEOW"
}

///|
test {
  let cat = Cat::{  }
  inspect(cat.make_sound(), content="meow")
  inspect(cat.make_loud_sound(), content="MEOW")
}