cgen: return if multi-return with bare function value uses function name as type #22
Description
A multi-return expression of type (T, fn () ...) fails when a bare function value flows through a return if expression. The generated multi-return struct field type is built from the function symbol name instead of the function type.
Using the function value in both branches is enough to trigger the issue.
Reproduction
module main
fn noop_cmd() int {
return 0
}
fn update(cond bool) (int, fn () int) {
return if cond {
1, noop_cmd
} else {
2, noop_cmd
}
}
fn main() {
a, c := update(true)
println(a)
println(c())
}
Actual Result
C compilation fails because the generated code treats main__noop_cmd as a type name:
error: unknown type name 'main__noop_cmd'
main__noop_cmd arg1;
In the original report, the same pattern produced bobatea__noop_cmd.
Expected Result
The program should compile, return the function value as fn () int, and print:
1
0
Repro Status
Reproduced on origin/master at a72a784ee, after #27342 was merged.
Original bugs.vlang.io source cluster: lilly app + bobatea TUI module.
[!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. [!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.