From c3f7fe39ec9c58889fc3e1b3319529cc343e0d59 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sun, 6 Aug 2023 18:18:48 +0800 Subject: [PATCH] checker: fix struct field fntype value call (#19067) --- vlib/v/checker/fn.v | 2 +- vlib/v/tests/struct_field_fn_call_test.v | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/struct_field_fn_call_test.v 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 +}