Skip to content

Commit

Permalink
checker: fix fntype var marked as auto heap (#22290)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Sep 24, 2024
1 parent 03e0b9e commit 07465a4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions vlib/v/tests/pointers/ref_callback_test.v
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 07465a4

Please sign in to comment.