checker: fix fntype var marked as auto heap (#22290)

This commit is contained in:
Felipe Pena 2024-09-24 00:54:02 -03:00 committed by GitHub
parent 03e0b9e646
commit 07465a4e7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View file

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

View file

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