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

Generic -- error: cannot convert 'int' to 'struct string' #23796

Open
vodish opened this issue Feb 23, 2025 · 5 comments
Open

Generic -- error: cannot convert 'int' to 'struct string' #23796

vodish opened this issue Feb 23, 2025 · 5 comments
Labels
Bug This tag is applied to issues which reports bugs. Comptime Features processed during compile time, like $if, $for, $env etc Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@vodish
Copy link

vodish commented Feb 23, 2025

Image

playground

https://play.vlang.io/p/b4d18365e5

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.

Copy link

Connected to Huly®: V_0.6-22206

@felipensp felipensp added Bug This tag is applied to issues which reports bugs. Comptime Features processed during compile time, like $if, $for, $env etc Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. and removed Unit: Checker Bugs/feature requests, that are related to the type checker. labels Feb 23, 2025
@felipensp
Copy link
Member

The checking must be $if field.typ is int { instead.

@felipensp felipensp removed Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Comptime Features processed during compile time, like $if, $for, $env etc labels Feb 23, 2025
@felipensp
Copy link
Member

It is not exactly an error, it is as the comptime stuff works. To avoid such error you have to prevent the assignment being generated to the wrong type, once it is traversing all fields of the struct with different types.

Maybe should we add some warning? notice? What do you think @medvednikov @spytheman

@felipensp felipensp added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Comptime Features processed during compile time, like $if, $for, $env etc labels Feb 25, 2025
@JalonSolov
Copy link
Contributor

It is an error in that you don't see any problems until the C compiler throws an error. V should always catch things that that (if it can), before it ever gets to the C compiler.

Think of it this way... if V can't catch it, what is the native backend supposed to do? Generate code that fails at runtime?

@Avey777
Copy link

Avey777 commented Feb 25, 2025

It is an error in that you don't see any problems until the C compiler throws an error. V should always catch things that that (if it can), before it ever gets to the C compiler.

Think of it this way... if V can't catch it, what is the native backend supposed to do? Generate code that fails at runtime?

It would be nice to optimize the prompt copy.

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. Comptime Features processed during compile time, like $if, $for, $env etc 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