Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: fix fntype var marked as auto heap #22290

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading