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
A tour of VxThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
E3060A task that can fail, used in a way that could lose its failure. A task whose body gives
Result<T, E> can fail, and its join() gives the T. When the task failed, the join leaves the tasks block, and the block gives the Err. So the task needs a handle, let h = spawn { .. };, and a join in its own block that always runs after the spawn. The block must give a Result<U, E> with the same E.
E3062A struct literal that writes its fields in an order other than the struct's declaration. The fields run in the order the source writes them, so P { y : f(), x : g() } would run f before g and store y before x. Write the fields in the order the struct declares them.