tests: cleanup go_anon_fn_variable_call_test.v (#13786)
parent
f5036629ca
commit
81bb1ea71f
|
@ -1,18 +1,35 @@
|
||||||
fn sum(a int, b int) int {
|
fn sum1(a int, b int) int {
|
||||||
// Simply proxy the function into an anonymous function for demo purposes
|
sum_func1 := fn (a int, b int) int {
|
||||||
sum_func := fn (a int, b int) int {
|
|
||||||
return a + b
|
return a + b
|
||||||
}
|
}
|
||||||
|
sum_func2 := sum_func1
|
||||||
|
|
||||||
// and run it concurrently
|
g := go sum_func2(a, b)
|
||||||
g := go sum_func(a, b)
|
|
||||||
|
result := g.wait()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add(a int, b int) int {
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sum2(a int, b int) int {
|
||||||
|
sum_func1 := add
|
||||||
|
sum_func2 := sum_func1
|
||||||
|
|
||||||
|
g := go sum_func2(a, b)
|
||||||
|
|
||||||
result := g.wait()
|
result := g.wait()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_go_anon_fn_variable_call() {
|
fn test_go_anon_fn_variable_call() {
|
||||||
ret := sum(22, 33)
|
ret1 := sum1(22, 33)
|
||||||
println(ret)
|
println(ret1)
|
||||||
assert ret == 55
|
assert ret1 == 55
|
||||||
|
|
||||||
|
ret2 := sum2(2, 3)
|
||||||
|
println(ret2)
|
||||||
|
assert ret2 == 5
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue