C error on returning generic anon fn result #31
Describe the bug
Running ./v -g -o vdbg cmd/v && ./vdbg 'generic_fn_return.v' && 'generic_fn_return' on generic_fn_return.v produced a compiler error.
Reproduction Steps
./v -g -o vdbg cmd/v && ./vdbg 'generic_fn_return.v' && 'generic_fn_return'
fn foo[T](do fn () !T) !T {
mut r := T{}
r = do()!
return r
}
fn main() {
docb := fn () !int {
return -1
}
r := foo(docb)!
assert r == -1
}
Expected Behavior
Successful compilation and passed assert.
Current Behavior
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/generic_fn_return.01KR1TN1DGENRFD9V8GM7MN9P3.tmp.c:8553: error: '{' expected (got ";")
=================================================================
Try passing `-g` when compiling, to see a .v file:line information, that correlates more with the C error.
(Alternatively, pass `-show-c-output`, to print the full C error message).
builder error:
==================
C error found while compiling generated C code.
This can be caused by invalid C interop code, C compiler flags, or a V compiler bug.
If your code is pure V and this still happens, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
Possible Solution
No response
Additional Information/Context
Generated by v bug from generic_fn_return.v.
V version
V 0.5.1 701d7f3
Environment details (OS name and version, etc.)
|V full version |V 0.5.1 2f3c0f1f397c08bfc5ef73e7ff62794471b2b811.701d7f3
|:-------------------|:-------------------
|OS |linux, Linux version 7.0.3-arch1-1 (linux@archlinux) (gcc (GCC) 15.2.1 20260209, GNU ld (GNU Binutils) 2.46) #1 SMP PREEMPT_DYNAMIC Thu, 30 Apr 2026 18:41:12 +0000
|Processor |16 cpus, 64bit, little endian, 12th Gen Intel(R) Core(TM) i5-1240P
|Memory |4.13GB/15.34GB
| |
|V executable |/home/ge/.vlang/v
|V last modified time|2026-05-07 18:19:14
| |
|V home dir |OK, value: /home/ge/.vlang
|VMODULES |OK, value: /home/ge/.vmodules
|VTMP |OK, value: /tmp/v_1000
|Current working dir |OK, value: /tmp
| |
|Git version |git version 2.54.0
|V git status |weekly.2026.03-1869-g701d7f37
|.git/config present |true
| |
|cc version |cc (GCC) 15.2.1 20260209
|gcc version |gcc (GCC) 15.2.1 20260209
|clang version |clang version 22.1.3
|tcc version |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.43