You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Accessing optional field in compile time code causes C error
Reproduction Steps
modulemaininterfaceTestInterface {
test_func() f64
}
structStruct1 {
num f64
}
fn (o &Struct1) test_func() f64 {
return o.num
}
structStruct2 {
s1?&Struct1
}
fndo_thing[T]() T {
t:= T{}
$for field in T.fields {
$if field.typ isTestInterface {
i:=TestInterface(t.$(field.name))
println('${i.test_func()}')
}
}
return t
}
pub fnmain() {
do_thing[Struct2]()
}
Expected Behavior
no C error
Current Behavior
C error:
PS C:\Users\jcwea\Documents\git\vtest> v run .
==================
C:/Users/jcwea/AppData/Local/Temp/v_0/vtest.01HQPQ5SW9NC7GKNV47M8KWAVT.tmp.c:6995: warning: implicit declaration of function 'tcc_backtrace'
C:/Users/jcwea/AppData/Local/Temp/v_0/vtest.01HQPQ5SW9NC7GKNV47M8KWAVT.tmp.c:13239: error: cannot convert 'struct _option_main__Struct1_ptr' to 'struct main__Struct1 *'
...
==================
(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
Possible Solution
The best solution is probably to not match ?T's with $if field.typ is T, thus never calling the code in the $if statement. But we would likely still want to be able to match these optional field types somehow, maybe with a $if field.underlying_typ is T or something similar. I image it could work the same way as unwrapping an alias or a sum type during compile time.
Additional Information/Context
affects vgdextension
V version
V 0.4.4 7df5646
Environment details (OS name and version, etc.)
V full version: V 0.4.4 1733dab.7df5646
OS: windows, Microsoft Windows 11 Pro v26058 64-bit
Processor: 24 cpus, 64bit, little endian,
getwd: C:\Users\jcwea\Documents\git\vtest
vexe: C:\Users\jcwea\Documents\git\v\v.exe
vexe mtime: 2024-02-27 22:26:52
vroot: OK, value: C:\Users\jcwea\Documents\git\v
VMODULES: OK, value: C:\Users\jcwea\.vmodules
VTMP: OK, value: C:\Users\jcwea\AppData\Local\Temp\v_0
Git version: git version 2.40.0.windows.1
Git vroot status: weekly.2024.09-4-g7df56462
.git/config present: true
CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.
thirdparty/tcc status: thirdparty-windows-amd64 b99a453d
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.
The text was updated successfully, but these errors were encountered:
Describe the bug
Accessing optional field in compile time code causes C error
Reproduction Steps
Expected Behavior
no C error
Current Behavior
C error:
Possible Solution
The best solution is probably to not match
?T
's with$if field.typ is T
, thus never calling the code in the $if statement. But we would likely still want to be able to match these optional field types somehow, maybe with a$if field.underlying_typ is T
or something similar. I image it could work the same way as unwrapping an alias or a sum type during compile time.Additional Information/Context
affects vgdextension
V version
V 0.4.4 7df5646
Environment details (OS name and version, etc.)
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.
The text was updated successfully, but these errors were encountered: