mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix wrong interface parameter resolution for anonymous fn (#18724)
This commit is contained in:
parent
f3942417c4
commit
329e063752
@ -1712,13 +1712,18 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||
for i, mut arg in node.args {
|
||||
targ := c.check_expr_opt_call(arg.expr, c.expr(arg.expr))
|
||||
arg.typ = targ
|
||||
earg_types << targ
|
||||
|
||||
param := if info.func.is_variadic && i >= info.func.params.len - 1 {
|
||||
info.func.params.last()
|
||||
} else {
|
||||
info.func.params[i]
|
||||
}
|
||||
if c.table.sym(param.typ).kind == .interface_ {
|
||||
// cannot hide interface expected type to make possible to pass its interface type automatically
|
||||
earg_types << param.typ.set_nr_muls(targ.nr_muls())
|
||||
} else {
|
||||
earg_types << targ
|
||||
}
|
||||
param_share := param.typ.share()
|
||||
if param_share == .shared_t
|
||||
&& (c.locked_names.len > 0 || c.rlocked_names.len > 0) {
|
||||
|
28
vlib/v/tests/iface_arg_test.v
Normal file
28
vlib/v/tests/iface_arg_test.v
Normal file
@ -0,0 +1,28 @@
|
||||
interface ITest {
|
||||
}
|
||||
|
||||
struct Test {
|
||||
}
|
||||
|
||||
struct Cmdable {
|
||||
mut:
|
||||
call fn (cmd ITest)
|
||||
}
|
||||
|
||||
fn (t Test) test(a ITest) {}
|
||||
|
||||
fn test(a ITest) {}
|
||||
|
||||
fn get() Test {
|
||||
return Test{}
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut a := Cmdable{}
|
||||
a.call = test
|
||||
a.call(Test{})
|
||||
test(Test{})
|
||||
Test{}.test(a)
|
||||
|
||||
assert true
|
||||
}
|
Loading…
Reference in New Issue
Block a user