From 7c7664e158d2b196a1b4dcc0e31008c307d3000d Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 23 Sep 2024 20:27:58 -0300 Subject: [PATCH] fix --- vlib/v/checker/checker.v | 2 +- vlib/v/tests/pointers/ref_callback_test.v | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/pointers/ref_callback_test.v 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 +}