From ab9aea2282bf2fac02732027f928bb6428f271d7 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 7 Jan 2024 22:58:09 -0300 Subject: [PATCH] cgen: fix wrong heap promoted arg detection (#20421) --- vlib/v/gen/c/fn.v | 1 + vlib/v/tests/fn_heap_promoted_test.v | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 vlib/v/tests/fn_heap_promoted_test.v diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index f391f266ea..1940fcd005 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -628,6 +628,7 @@ fn (mut g Gen) fn_decl_params(params []ast.Param, scope &ast.Scope, is_variadic g.definitions.write_string(')') fparams << caname fparamtypes << param_type_name + heap_promoted << false } else { mut heap_prom := false if scope != unsafe { nil } { diff --git a/vlib/v/tests/fn_heap_promoted_test.v b/vlib/v/tests/fn_heap_promoted_test.v new file mode 100644 index 0000000000..32cf69bf14 --- /dev/null +++ b/vlib/v/tests/fn_heap_promoted_test.v @@ -0,0 +1,17 @@ +@[heap] +struct Context {} + +type Method = fn (ctx Context) + +fn call(method Method, ctx Context) { // or switch `ctx` and `method` also ok + method(ctx) +} + +fn get(ctx Context) { + println('ok') +} + +fn test_main() { + call(get, Context{}) + assert true +}