diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 7b2d2a7698..957c4252b2 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1779,7 +1779,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { // cannot hide interface expected type to make possible to pass its interface type automatically earg_types << if targ.idx() != param.typ.idx() { param.typ } else { targ } } else { - earg_types << targ + earg_types << param.typ } param_share := param.typ.share() if param_share == .shared_t diff --git a/vlib/v/tests/struct_field_fn_call_test.v b/vlib/v/tests/struct_field_fn_call_test.v new file mode 100644 index 0000000000..ba4eafb6e1 --- /dev/null +++ b/vlib/v/tests/struct_field_fn_call_test.v @@ -0,0 +1,18 @@ +struct Foo { + f fn (Foo) int = dummy +} + +fn dummy(s Foo) int { + return 22 +} + +fn (mut s Foo) fun() int { + return s.f(s) +} + +fn test_struct_field_fn_call() { + mut s := Foo{} + ret := s.fun() + println(ret) + assert ret == 22 +}