cgen: fix wrong heap promoted arg detection (#20421)

This commit is contained in:
Felipe Pena 2024-01-07 22:58:09 -03:00 committed by GitHub
parent 1c11f13f28
commit ab9aea2282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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 } {

View File

@ -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
}