parent
							
								
									5f1eaaf3b1
								
							
						
					
					
						commit
						f87f8ec3f7
					
				| 
						 | 
				
			
			@ -345,11 +345,13 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
 | 
			
		|||
						}
 | 
			
		||||
					}
 | 
			
		||||
					info := var.obj as ast.Var
 | 
			
		||||
					if g.table.get_type_symbol(info.typ).kind != .function {
 | 
			
		||||
						g.writeln('${g.typ(info.typ)}$deref $var.name;')
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if is_live_wrap {
 | 
			
		||||
		// The live function just calls its implementation dual, while ensuring
 | 
			
		||||
		// that the call is wrapped by the mutex lock & unlock calls.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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