v
v copied to clipboard
func variable pass in anonymous func error
V version: OS:
What did you do? https://devbits.app/play/GGmC8FzzOxSI
module main
fn test() {
println('test')
}
fn test2() {
println('test2')
}
fn main() {
t1 := test
t2 := test2
anon := fn[t1,t2] () {
t1()
t2()
}
anon()
}
What did you expect to see? error that not undefined or not error else
What did you see instead?
error that error: unknown function:
Interesting workaround is to wrap the functions in a structure and pass that into the anon function 🫢.
module main
struct Fun{
t1 fn()
t2 fn()
}
fn test() {
println('test')
}
fn test2() {
println('test2')
}
fn main() {
funs := Fun{ test, test2 }
anon := fn[funs] () {
funs.t1()
funs.t2()
}
anon()
}