From 072364fc597ff038daca4fbd2fc24af244799f6f Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 5 Jul 2023 17:26:44 -0300 Subject: [PATCH] checker: fix interface param resolution (#18780) --- vlib/v/checker/fn.v | 2 +- vlib/v/tests/iface_arg_test.v | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 53ab2905c6..96d72ed4ad 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1723,7 +1723,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { } 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()) + earg_types << if targ.idx() != param.typ.idx() { param.typ } else { targ } } else { earg_types << targ } diff --git a/vlib/v/tests/iface_arg_test.v b/vlib/v/tests/iface_arg_test.v index cf4b7e6fc0..9405918744 100644 --- a/vlib/v/tests/iface_arg_test.v +++ b/vlib/v/tests/iface_arg_test.v @@ -13,8 +13,8 @@ fn (t Test) test(a ITest) {} fn test(a ITest) {} -fn get() Test { - return Test{} +fn get() &Test { + return &Test{} } fn test_main() { @@ -26,3 +26,11 @@ fn test_main() { assert true } + +fn test_ptr() { + mut a := Cmdable{} + a.call = test + a.call(get()) + + assert true +}