False errors when initializing an embedded C struct that contains a reference. #21046
Labels
Bug
This tag is applied to issues which reports bugs.
Unit: Checker
Bugs/feature requests, that are related to the type checker.
Describe the bug
When declaring a
struct C.MyCStruct
with any name, that has a reference inside it, and embedding that struct inside a wrapper, initializing the wrapper doesn't work unless both the MyCStruct field and the inner fields are initialized.Reproduction Steps
Expected Behavior
The above code should the following error:
Removing either field initializer should make it wrap the struct as expected.
Current Behavior
The incorrect code sample given actually compiles without error, generating the designated initializer
((main__MyWrapper){.MyCStruct = it,})
What's worse, though, is if you remove
MyCStruct
from the struct literal, leaving only the initializer for thedata
field you get this error message:And if you remove the
data
field, leaving theMyCStruct: it
field, you get two error messages:If the inner type is not a C struct, e.g. replacing
C.MyCStruct
withMyNormalStruct
then all three of these cases work as expected of course, but it is worth noting that when both fields are removed from theMyWrapper
struct literal it also gives two errors rather than one, but I can't tell whether that is intentional or not. The errors:Possible Solution
The check that all reference fields were initialized seems to have a bug in it, that only comes up when the embedded struct is a C struct.
Additional Information/Context
I was taking a C struct from my old codebase and giving it some iterator wrappers. The wrappers worked, but I had to write this seemingly incorrect struct literal to make it work!
V version
V 0.4.4 549654a
Environment details (OS name and version, etc.)
V full version: V 0.4.4 386bd77.549654a
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 4 cpus, 64bit, little endian,
getwd: C:\Users\Owner
vexe: C:\Program Files\v\v.exe
vexe mtime: 2024-03-17 05:49:07
vroot: contains spaces, value: C:\Program Files\v
VMODULES: OK, value: C:\Users\Owner.vmodules
VTMP: OK, value: C:\Users\Owner\AppData\Local\Temp\v_0
Git version: git version 2.37.2.windows.2
Git vroot status: weekly.2024.11-39-g549654ae
.git/config present: true
CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.
thirdparty/tcc: N/A
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: