mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
5f1eaaf3b1
commit
f87f8ec3f7
@ -345,7 +345,9 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
|
||||
}
|
||||
}
|
||||
info := var.obj as ast.Var
|
||||
g.writeln('${g.typ(info.typ)}$deref $var.name;')
|
||||
if g.table.get_type_symbol(info.typ).kind != .function {
|
||||
g.writeln('${g.typ(info.typ)}$deref $var.name;')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
vlib/v/tests/defer/defer_with_fn_var_test.v
Normal file
37
vlib/v/tests/defer/defer_with_fn_var_test.v
Normal file
@ -0,0 +1,37 @@
|
||||
[has_globals]
|
||||
module main
|
||||
|
||||
__global fcall_count = int(0)
|
||||
|
||||
fn f1() {
|
||||
println(1)
|
||||
fcall_count++
|
||||
}
|
||||
|
||||
fn f2() {
|
||||
println(2)
|
||||
fcall_count++
|
||||
}
|
||||
|
||||
fn f3(f fn ()) {
|
||||
f()
|
||||
}
|
||||
|
||||
fn func_defer() {
|
||||
mut func := f1
|
||||
println('Before')
|
||||
defer {
|
||||
func()
|
||||
}
|
||||
defer {
|
||||
f3(func)
|
||||
}
|
||||
func = f2
|
||||
println('After')
|
||||
assert true
|
||||
}
|
||||
|
||||
fn test_defer_with_fn_var() {
|
||||
func_defer()
|
||||
assert fcall_count == 2
|
||||
}
|
Loading…
Reference in New Issue
Block a user