-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
@typeName returns struct definition for tuples #23292
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
Comments
see #19858 (comment) on generating a type ID. Note that
Also, do you really need a type ID or can you require that the user must specify all components they wish to use upfront then take a MultiArrayList approach? |
this behavior is likely expected because tuples exhibit structural equality and are not unique to the declaration where theyre defined. |
Working as intended. Please refrain from using |
I think this raises a deeper issue: It would be really cool if Zig had a way to uniquely identify named types at runtime. The recommended way of generating a type ID does not actually work: if I have two separate tuple structs with the same definition, they generate the same type ID. While there is an argument to be made that this is intended because the types are the same, I think it is also totally reasonable to want differently-named types to have different IDs. For now, I think I'll just add a constant Update: Adding an ID field is not actually possible! Tuples do not allow declarations. |
How else would you recommend doing safety-checked any-pointer-to-known-type casting? This is something people rely on in the wild: https://github.com/ikskuh/any-pointer (I'm using this to implement ECMAScript's |
@tauoverpi's comment links to code that can be used to generate type ids. are there ways this falls short for you? |
Zig Version
0.15.0-dev.64+2a4e06bcb
Steps to Reproduce and Observed Behavior
Compiling and running the following source will reproduce the unexpected behaviour:
Output when run:
Expected Behavior
The tuple struct should be named, just like a regular struct. Expected output:
I first noticed this bug in 0.14. I would expect that
@typeName
returns the name of the tuple, instead of its definition. Some motivation as to why this matters for me: I'm writing an ECS and I want the end-user to be able to use any type for a component. Thus, I need an ID that is unique per-type at runtime. Since Zig does not have a type ID builtin, I figured@typeName
should do the trick. This works perfectly for structs, but not for tuple structs.The text was updated successfully, but these errors were encountered: