diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 2f0b155b92bb0a..40bfc7a0991c38 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -4376,6 +4376,13 @@ fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool) { } } .sum_type, .interface_ {} + .function { + if type_sym.info is ast.FnType { + if type_sym.info.is_anon { + node.obj.is_auto_heap = true + } + } + } else { node.obj.is_auto_heap = true } diff --git a/vlib/v/tests/pointers/ref_callback_test.v b/vlib/v/tests/pointers/ref_callback_test.v new file mode 100644 index 00000000000000..6035f5740ce119 --- /dev/null +++ b/vlib/v/tests/pointers/ref_callback_test.v @@ -0,0 +1,20 @@ +module main + +struct Struct_voidptr { + func voidptr +} + +fn function() string { + return 'Function!' +} + +fn test_main() { + fun := function + + sct := Struct_voidptr{ + func: &fun + } + + assert fun() == 'Function!' + assert sct.func == &fun +}