v
v copied to clipboard
C error when using comp time $if $else
Describe the bug
I get these errors when I run this code. Specifically the part that creates a new Test2 is what causes it. The code runs fine when that line is omitted. It also has something to do with being nested structs because _ := Test{} compiles and runs fine.
C:/Users/imado/AppData/Local/Temp/v_0/bug.2883217358017684869.tmp.c:494: warning: WINVER redefined
C:/Users/imado/AppData/Local/Temp/v_0/bug.2883217358017684869.tmp.c:6837: warning: implicit declaration of function 'tcc_backtrace'
C:/Users/imado/AppData/Local/Temp/v_0/bug.2883217358017684869.tmp.c:7585: warning: assignment from incompatible pointer type
C:/Users/imado/AppData/Local/Temp/v_0/bug.2883217358017684869.tmp.c:7585: warning: assignment makes pointer from integer without a cast
C:/Users/imado/AppData/Local/Temp/v_0/bug.2883217358017684869.tmp.c:7585: warning: cast between pointer and integer of different size
C:/Users/imado/AppData/Local/Temp/v_0/bug.2883217358017684869.tmp.c:12447: error: ',' expected (got ";")
Expected Behavior
Expected code to compile.
Current Behavior
Produces C error
Reproduction Steps
struct Test {
debug bool = $if debug { true } $else { false }
}
struct Test2 {
test Test
}
fn main() {
_ := Test2{}
}
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.3.3 b7b6c23
Environment details (OS name and version, etc.)
V 0.3.3 b7b6c23 PS C:\Users\imado> v doctor OS: windows, Microsoft Windows 11 Pro v22621 64-bit Processor: 16 cpus, 64bit, little endian, CC version: Error: exec failed (CreateProcess) with code 2: The system cannot find the file specified. cmd: cc --version
getwd: C:\Users\imado vmodules: C:\Users\imado.vmodules vroot: C:\Users\imado\v vexe: C:\Users\imado\v\v.exe vexe mtime: 2023-02-28 03:35:39 is vroot writable: true is vmodules writable: true V full version: V 0.3.3 b7b6c23
Git version: git version 2.33.1.windows.1 Git vroot status: weekly.2023.09-4-gb7b6c236 .git/config present: true thirdparty/tcc status: thirdparty-windows-amd64 1e6e7c6f
It also works cleanly if you embed Test into Test2, instead of declaring a field of type Test. In other words,
struct Test {
debug bool = $if debug { true } $else { false }
}
struct Test2 {
Test
}
fn main() {
_ := Test2{}
}
It only fails with your original code.