diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 2f0b155b92bb0a..562c082d06143d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -4375,7 +4375,7 @@ fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool) { node.obj.is_auto_heap = true } } - .sum_type, .interface_ {} + .sum_type, .interface_, .function {} 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 +}