mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
checker: fix fntype var marked as auto heap (#22290)
This commit is contained in:
parent
03e0b9e646
commit
07465a4e7d
2 changed files with 27 additions and 0 deletions
|
@ -4376,6 +4376,13 @@ fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sum_type, .interface_ {}
|
.sum_type, .interface_ {}
|
||||||
|
.function {
|
||||||
|
if type_sym.info is ast.FnType {
|
||||||
|
if type_sym.info.is_anon {
|
||||||
|
node.obj.is_auto_heap = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
node.obj.is_auto_heap = true
|
node.obj.is_auto_heap = true
|
||||||
}
|
}
|
||||||
|
|
20
vlib/v/tests/pointers/ref_callback_test.v
Normal file
20
vlib/v/tests/pointers/ref_callback_test.v
Normal 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
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue