E3061

E3061 — An impl of a trait does not write a method that the trait requires: one the trait declares with no default body. A call to that method would otherwise fail where it is called, with "method not found", though the fault is in the impl.

What the compiler reports

Error[E3061]{{.*}}`impl Counter for i32` does not write the method 'other' that trait Counter requires
1 error(s) emitted

The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.

A program that triggers it

//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
// An impl must write each method that its trait declares with no default body. `Counter`
// requires `next` and `other`, and gives `reset` a default body, so only `other` is missing.
// This program used to compile and print 7.

trait Counter {
  fn next(self : Self) -> i64;
  fn other(self : Self) -> i64;
  fn reset(self : Self) -> i64 {
    return 0;
  }
}

impl Counter for i32 {
  fn next(self : i32) -> i64 {
    return 7;
  }
}

fn main() -> i32 {
  let a : i32 = 1;
  print(a.next());
  return 0;
}

From tests/frontend/fail/an_impl_must_write_each_required_method.vx, which asserts this diagnostic on every commit.

Related