cgen, coroutines: go expr handle references undeclared thread__tN C variable #23
Description
With -use-coroutines, a go expr whose handle is stored/used makes cgen reference a C variable thread__tN that it never declares, so the generated C fails to compile.
V version: V 0.5.1, current master (27f394507)
OS/Backend: reproduced on macOS arm64; originally reported on Linux/cc. Requires -use-coroutines.
Reproducer
struct App {
mut:
worker thread
}
fn (a App) loop() {}
fn main() {
mut a := App{}
a.worker = go a.loop()
a.worker.wait()
}
Compile with:
v -use-coroutines file.v
Current behavior
C compilation fails — V references an undeclared thread__tN:
error: use of undeclared identifier 'thread__t2'
4112 | thread__t2;
The generated C for the coroutine handle is:
a.worker = /*go (coroutine) */ thread__t2;
The coroutine branch emits the photon_thread_create_and_migrate_to_work_pool(...) call but never declares the thread__tN handle variable it then reads.
Expected behavior
Compiles and runs (as the non-coroutine spawn path does).
Notes
- Reported via the bugs.vlang.io crash reporter (original symbol
thread__t4, fromdb.flush_thread = go db.flush_loop()). - Likely in
vlib/v/gen/c/spawn_and_go.v: theis_go(coroutine) branch sets the handle expression tothread_${tmp}without emitting its declaration, unlike the regularspawnpath.