You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
linux, Linux version 6.17.12-300.fc43.x86_64 (mockbuild@008798550d8d49b8909ac02baf9be783) (gcc (GCC) 15.2.1 20251111 (Red Hat 15.2.1-4), GNU ld version 2.45.1-1.fc43) #1 SMP PREEMPT_DYNAMIC Sat Dec 13 05:06:24 UTC 2025
tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status
thirdparty-linux-amd64 696c1d84
emcc version
N/A
glibc version
ldd (GNU libc) 2.42
What did you do? ./v -g -o vdbg cmd/v && ./vdbg main.v && main
modulemainfnf_a() {
println('a')
}
fnmain() {
f:= f_a
ref:=&f
println('ref=0x${ptr_str(ref)}')
handler:=fn [ref] () { // ref_fn is captured as a direct function pointer (*fn) instead of a pointer to a function (**fn)println('in closure: ref=0x${ptr_str(ref)}')
deref_fn:=*ref
println('in closure: deref=0x${ptr_str(deref_fn)}')
deref_fn()
}
f()
deref:=*ref
println('deref=0x${ptr_str(deref)}')
deref()
handler()
}
What did you see?
ref=0x7ffeee063e48
a
deref=0x6154a2
a
in closure: ref=0x7ffeee063e48
in closure: deref=0x7ffeee063e48
0x7ffeee063e48: at ???: RUNTIME ERROR: invalid memory access
/tmp/v_1000/main.01KCXM2D5X0V8P114VXM772JFX.tmp.c:5182: by main__main
/tmp/v_1000/main.01KCXM2D5X0V8P114VXM772JFX.tmp.c:5260: by main
What did you expect to see?
A successful call to the reference of the function captured in the closure.
Additional investigation
The generated code for the closure is correct but for the type of the function reference in the anonymous function structure:
This bug follows on #25940
V version: V 0.4.12 60f7c81, press to see full `v doctor` output
What did you do?
./v -g -o vdbg cmd/v && ./vdbg main.v && mainWhat did you see?
What did you expect to see?
A successful call to the reference of the function captured in the closure.
Additional investigation
The generated code for the closure is correct but for the type of the function reference in the anonymous function structure:
Should be:
This only change solves the issue.
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.