-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cgen bug when using generics with C types #23374
Comments
I got interest in your issue because I am working in a USB project which uses libudev. First, the problem is not related with generics but in the way you call Your code reduced: #include <libudev.h>
struct C.udev {}
fn main() {
_ := C.udev{}
} Produced this (with gcc which gives more info):
Then I googled about the message has initializer but incomplete type, make tests and arrive to this: module main
#pkgconfig libudev // -ludev
#include <libudev.h>
struct C.udev{}
type Udev = C.udev // make V's type
// _public_ struct udev *udev_new(void) {
fn C.udev_new() &C.udev
fn new_udev() &Udev { // V builder
return C.udev_new()
}
fn generic[T](val T) &T {
return &val
}
fn main() {
u := new_udev()
println('u ${u}')
g := generic(u)
println('g ${g}')
} produces (gcc or tcc now):
The pkgconfig is for the linker. What I learned:
I expect more explanations from the team to learn more. |
You method of creating the udev is indeed correct, I was trying to select a type that was easily accessible and missed the correct method. #pkgconfig libudev
#include <libudev.h>
struct C.udev {}
fn C.udev_new() &C.udev
fn new_udev() &C.udev {
return C.udev_new()
}
fn generic[T](val T) &T {
return &val
}
fn main() {
u := new_udev()
r := generic(u)
} This will produce:
Which makes the errors with generics more clear. |
You are right, any C error should be fixed. The alias conversion of C type to V is a workaround for now. Let see if the team decides to do the conversion for us or mark as invalid the use of structs coming from C, JS or the other backends for the generics. |
V doctor:
What did you do?
./v -g -o vdbg cmd/v && ./vdbg test.v && test
What did you see?
What did you expect to see?
compile successfully
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.
Huly®: V_0.6-21805
The text was updated successfully, but these errors were encountered: