Skip to content

Commit 51f5841

Browse files
authored
checker: do not deref non-pointer types in fn_signature_using_aliases (#12340)
1 parent 28cada3 commit 51f5841

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

vlib/v/ast/types.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,9 @@ pub fn (t &Table) fn_signature_using_aliases(func &Fn, import_aliases map[string
11501150
param := func.params[i]
11511151
mut typ := param.typ
11521152
if param.is_mut {
1153-
typ = typ.deref()
1153+
if param.typ.is_ptr() {
1154+
typ = typ.deref()
1155+
}
11541156
sb.write_string('mut ')
11551157
}
11561158
if !opts.type_only {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
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`
2+
13 |
3+
14 | fn bar() {
4+
15 | foo(St{})
5+
| ~~~~
6+
16 | }
7+
Details: main.Interface has `fn method(mut x main.Interface) u32`
8+
main.St has `fn method(st main.St) int`
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
interface Interface {
2+
mut:
3+
method() u32
4+
}
5+
6+
struct St {}
7+
8+
fn (st St) method() int {
9+
panic('')
10+
}
11+
12+
fn foo(_ Interface) {}
13+
14+
fn bar() {
15+
foo(St{})
16+
}

0 commit comments

Comments
 (0)