Skip to content
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

Confusing errors when printing a C struct #19512

Closed
jrfondren opened this issue Oct 5, 2023 · 4 comments
Closed

Confusing errors when printing a C struct #19512

jrfondren opened this issue Oct 5, 2023 · 4 comments
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@jrfondren
Copy link
Contributor

jrfondren commented Oct 5, 2023

Describe the bug

v generates C code with _str functions that fail with "incomplete type" errors if a C struct is printed, and this isn't communicated well by v's error message.

Reproduction Steps

Try to compile this example program

struct C.example { }

fn main() {
        println(C.example{})
}

Expected Behavior

An error from v about not being able to print the struct.

Current Behavior

$ v -o example example.c.v
tcc.exe: arm64-gen.c:351: arm64_ldrs: Assertion `0' failed.
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error. This should never happen.
$ v example.c.v && LANG=C gcc example.c
...
example.c:2050:50: error: parameter 1 ('it') has incomplete type
 2050 | static string struct__example_str(struct example it) { return indent_struct__example_str(it, 0);}
...

Possible Solution

No response

Additional Information/Context

This error can reasonably happen when println() is used in placeholder code to ensure a variable is used:

#flag -lwayland-client
#include <wayland-client.h>

struct C.wl_display { }
fn C.wl_display_connect(&char) &C.wl_display

fn main() {
        mut wl := C.wl_display_connect(unsafe { nil })
        println('this works so far')
}

This prints a warning as the variable wl is used. I added a println(wl) to silence that for the moment and the strange error had me thinking I had some worse problem.

V version

V 0.4.2 5c37c31

Environment details (OS name and version, etc.)

OS: linux
Processor: 4 cpus, 64bit, little endian, aarch64
CC version: cc (GCC) 12.1.0
thirdparty/tcc status: thirdparty-linux-aarch64 dd547903

Note

You can vote for this issue using the 👍 reaction. More votes increase the issue's priority for developers.

Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.

@jrfondren jrfondren added the Bug This tag is applied to issues which reports bugs. label Oct 5, 2023
@ArtemkaKun ArtemkaKun added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Build V build error on any OS/CPU architecture. labels Oct 5, 2023
@ArtemkaKun
Copy link
Contributor

You have arm64 processor. Do you have PC or you run it from Termux?

@jrfondren
Copy link
Contributor Author

I have an ARM Linux laptop, from pine64.com. V runs out of the box on the provided Arch image.

@Delta456
Copy link
Member

On x84-64

==================
/tmp/v_1000/file.13233380909043727445.tmp.c:12655: error: too many initializers
...
==================
(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

@felipensp
Copy link
Member

Can you try again with a newer version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Build V build error on any OS/CPU architecture. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

No branches or pull requests

4 participants