checker: do not deref non-pointer types in `fn_signature_using_aliases` (#12340)

pull/12356/head
Lucas Jenß 2021-11-01 00:26:15 +01:00 committed by GitHub
parent 28cada3fd5
commit 51f5841b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -1150,7 +1150,9 @@ pub fn (t &Table) fn_signature_using_aliases(func &Fn, import_aliases map[string
param := func.params[i]
mut typ := param.typ
if param.is_mut {
typ = typ.deref()
if param.typ.is_ptr() {
typ = typ.deref()
}
sb.write_string('mut ')
}
if !opts.type_only {

View File

@ -0,0 +1,8 @@
vlib/v/checker/tests/interface_sameness_check_for_mutable_methods.vv:15:6: error: `St` incorrectly implements method `method` of interface `Interface`: expected return type `u32`
13 |
14 | fn bar() {
15 | foo(St{})
| ~~~~
16 | }
Details: main.Interface has `fn method(mut x main.Interface) u32`
main.St has `fn method(st main.St) int`

View File

@ -0,0 +1,16 @@
interface Interface {
mut:
method() u32
}
struct St {}
fn (st St) method() int {
panic('')
}
fn foo(_ Interface) {}
fn bar() {
foo(St{})
}