From 890fb2d09d7f9e2d32d310d07c766e7a6db167e4 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 14 Jan 2021 18:50:06 +0000 Subject: [PATCH] checker: show signature for interface method on error (#8111) --- vlib/v/checker/checker.v | 3 +++ vlib/v/checker/tests/unimplemented_interface_b.out | 1 + vlib/v/checker/tests/unimplemented_interface_c.out | 1 + vlib/v/checker/tests/unimplemented_interface_d.out | 1 + vlib/v/checker/tests/unimplemented_interface_e.out | 1 + vlib/v/checker/tests/unimplemented_interface_f.out | 1 + 6 files changed, 8 insertions(+) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 489fa15e11..08725970f0 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1851,6 +1851,8 @@ fn (mut c Checker) type_implements(typ table.Type, inter_typ table.Type, pos tok if method := typ_sym.find_method(imethod.name) { msg := c.table.is_same_method(imethod, method) if msg.len > 0 { + sig := c.table.fn_signature(imethod, skip_receiver: true) + c.add_error_detail('$inter_sym.name has `$sig`') c.error('`$styp` incorrectly implements method `$imethod.name` of interface `$inter_sym.name`: $msg', pos) return false @@ -4907,6 +4909,7 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) table.Type { return map_type } +// call this *before* calling error or warn pub fn (mut c Checker) add_error_detail(s string) { c.error_details << s } diff --git a/vlib/v/checker/tests/unimplemented_interface_b.out b/vlib/v/checker/tests/unimplemented_interface_b.out index 9a95f12bf7..332f23214e 100644 --- a/vlib/v/checker/tests/unimplemented_interface_b.out +++ b/vlib/v/checker/tests/unimplemented_interface_b.out @@ -4,3 +4,4 @@ vlib/v/checker/tests/unimplemented_interface_b.vv:13:6: error: `Cat` incorrectly 13 | foo(c) | ^ 14 | } +details: main.Animal has `name() string` diff --git a/vlib/v/checker/tests/unimplemented_interface_c.out b/vlib/v/checker/tests/unimplemented_interface_c.out index 6c88e28201..c60a8facc2 100644 --- a/vlib/v/checker/tests/unimplemented_interface_c.out +++ b/vlib/v/checker/tests/unimplemented_interface_c.out @@ -4,3 +4,4 @@ vlib/v/checker/tests/unimplemented_interface_c.vv:12:6: error: `Cat` incorrectly 12 | foo(Cat{}) | ~~~~~ 13 | } +details: main.Animal has `name()` diff --git a/vlib/v/checker/tests/unimplemented_interface_d.out b/vlib/v/checker/tests/unimplemented_interface_d.out index 506f7f51b0..c219ff8cd6 100644 --- a/vlib/v/checker/tests/unimplemented_interface_d.out +++ b/vlib/v/checker/tests/unimplemented_interface_d.out @@ -4,3 +4,4 @@ vlib/v/checker/tests/unimplemented_interface_d.vv:12:6: error: `Cat` incorrectly 12 | foo(Cat{}) | ~~~~~ 13 | } +details: main.Animal has `speak(s string)` diff --git a/vlib/v/checker/tests/unimplemented_interface_e.out b/vlib/v/checker/tests/unimplemented_interface_e.out index b240dd4c81..49d1fe3512 100644 --- a/vlib/v/checker/tests/unimplemented_interface_e.out +++ b/vlib/v/checker/tests/unimplemented_interface_e.out @@ -4,3 +4,4 @@ vlib/v/checker/tests/unimplemented_interface_e.vv:12:6: error: `Cat` incorrectly 12 | foo(Cat{}) | ~~~~~ 13 | } +details: main.Animal has `speak(s string)` diff --git a/vlib/v/checker/tests/unimplemented_interface_f.out b/vlib/v/checker/tests/unimplemented_interface_f.out index 9ed8bec110..58b29e1fbf 100644 --- a/vlib/v/checker/tests/unimplemented_interface_f.out +++ b/vlib/v/checker/tests/unimplemented_interface_f.out @@ -4,3 +4,4 @@ vlib/v/checker/tests/unimplemented_interface_f.vv:11:13: error: `Cat` incorrectl 11 | animals << Cat{} | ~~~~~ 12 | } +details: main.Animal has `speak(s string)`