E4063#

Type does not implement trait, although an impl is defined.

This error can be further divided into 5 cases:

  • Method is missing

  • Implementation is private

  • Method type mismatch

  • Constraints are not satisfied

  • Method contains unresolved type parameters

Erroneous example#

Method is missing#

///|
trait Number {
  to_int(Self) -> Int
  to_float(Self) -> Float
}

///|
struct A(Int)

///|
impl Number for A with to_int(self : A) -> Int {
  //^~~~~~~~~~~~~~~
  // Error: Type A does not implement trait Number, although an `impl` is defined.
  // hint:
  //   method to_float is missing.
  self.0
}

Suggestion#

Modify the code according to the hint provided along with the error message. For the example above, you can add the missing method to_float to type A.

///|
priv trait Number {
  to_int(Self) -> Int
  to_float(Self) -> Float
}

///|
priv struct A(Int)

///|
impl Number for A with to_int(self : A) -> Int {
  self.0
}

///|
impl Number for A with to_float(self : A) -> Float {
  Float::from_int(self.0)
}

///|
test {
  let value : A = A(42)
  inspect(value.to_int(), content="42")
  ignore(value.to_float())
}