1
0
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:
Felipe Pena 2023-07-02 08:18:53 -03:00 committed by GitHub
parent f3942417c4
commit 329e063752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -1712,13 +1712,18 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
for i, mut arg in node.args { for i, mut arg in node.args {
targ := c.check_expr_opt_call(arg.expr, c.expr(arg.expr)) targ := c.check_expr_opt_call(arg.expr, c.expr(arg.expr))
arg.typ = targ arg.typ = targ
earg_types << targ
param := if info.func.is_variadic && i >= info.func.params.len - 1 { param := if info.func.is_variadic && i >= info.func.params.len - 1 {
info.func.params.last() info.func.params.last()
} else { } else {
info.func.params[i] 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() param_share := param.typ.share()
if param_share == .shared_t if param_share == .shared_t
&& (c.locked_names.len > 0 || c.rlocked_names.len > 0) { && (c.locked_names.len > 0 || c.rlocked_names.len > 0) {

View 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
}