From c7cde347b342b9bb0239b4def7584bee40134710 Mon Sep 17 00:00:00 2001 From: yuyi <yuyi98@163.com> Date: Thu, 22 Feb 2024 23:32:25 +0800 Subject: [PATCH] checker: fix struct field init with generic anon fn --- ...uct_field_init_with_generic_anon_fn_test.v | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 vlib/v/tests/struct_field_init_with_generic_anon_fn_test.v diff --git a/vlib/v/tests/struct_field_init_with_generic_anon_fn_test.v b/vlib/v/tests/struct_field_init_with_generic_anon_fn_test.v new file mode 100644 index 00000000000000..c6e5fc45015eda --- /dev/null +++ b/vlib/v/tests/struct_field_init_with_generic_anon_fn_test.v @@ -0,0 +1,30 @@ +pub struct Module { +} + +pub struct Service { + callback fn () = unsafe { nil } +} + +pub fn (mut self Module) do_anything[T]() { +} + +pub fn (mut self Module) register[T]() { + _ := Service{ + callback: fn [mut self] [T]() { + self.do_anything[T]() + } + } +} + +struct Something { +} + +struct SomethingDifferent { +} + +fn test_struct_field_init_with_generic_anon_fn() { + mut mod := Module{} + mod.register[Something]() + mod.register[SomethingDifferent]() + assert true +}