v
v copied to clipboard
cgen: wrong C generated code for SQL expr returning Result
Describe the bug
When I compile my code, I get a C error so my code can't compile.
Expected Behavior
The code to compile.
Current Behavior
==================
/tmp/v_1000/report_bug.3022669868040815997.tmp.c:16177: error: ',' expected (got ";")
...
==================
(Use `v -cg` to print the entire error message)
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang
Reproduction Steps
module main
import db.sqlite
struct Account {
id int [nonnull; primary]
}
fn main() {
db := sqlite.connect("test.db")!
sql db {
create table Account
}
get_account_by_id(db)!
}
fn get_account_by_id(db sqlite.DB) !Account {
return sql db {
select from Account where id == 1 limit 1
}
}
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.3.3 9826310
Environment details (OS name and version, etc.)
OS: linux, "Garuda Linux" Processor: 2 cpus, 64bit, little endian, Intel(R) Celeron(R) N4020 CPU @ 1.10GHz CC version: cc (GCC) 12.2.1 20230201
getwd: /home/riccardo vmodules: /home/riccardo/.vmodules vroot: /home/riccardo/v vexe: /home/riccardo/v/v vexe mtime: 2023-03-07 11:24:16 is vroot writable: true is vmodules writable: true V full version: V 0.3.3 9826310
Git version: git version 2.39.2 Git vroot status: weekly.2023.10-4-g98263108 (59 commit(s) behind V master) .git/config present: true thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
The error is on the select statement, but V should definitely telling you why, instead of showing a C error.
And it only causes an error when the function returns !Account, not when it returns Account
Fixed in #17871