-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Change builtins to return a string literal #8636
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tagName
and @errorName
should both return a null terminated slice instead since they can be used with runtime known arguments and returning different types based on whether they are being executed at comptime
or not is bad for generic code.
Looks like @andrewrk was the one to suggest that we use pointers to arrays when the length is comptime known (see #3779 (comment)). I can see how this could cause some issues with generic code, but I think sometimes this information is necessary, so I don't see much choice other than to expose it. |
I assumed he was referring to |
Yes, I took that comment as reference, and probably misunderstood it, and here we are. 😄
Just for extra n00b-friendly clarity, the desire is to ensure these builtins all return |
This change should also apply to all the strings in |
Are you still interested in finishing this pr? I'd be happy to do it for you if not. |
Sorry, yeah, I'd like to work on this. I got busy with real life and now I have a scary rebase in front of me 😄 I'll update this PR as soon as possible and ping the thread. |
This was already the case, but the documentation failed to point out that the returned value is of type `*const [N:0]u8`, i.e. that of a string literal. Also adds a behavioral test to assert that this is the case.
This is for consistency with the documentation on sentinel-terminated {arrays,slices,pointers} which already use `N` for a comptime-inferred size rather than `X`. Also adds a behavioral test to assert that a string literal is returned.
I have updated the PR and it seems to pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far, do you also want to make the change to @typeInfo
and @src
?
I have local changes ready to update string fields contained in structures returned by these two builtins to But while applying changes to zig/test/behavior/bugs/6456.zig Line 20 in e006281
Would you say this is WAI? EDIT: to clarify, this seems to make it impossible to use a similar pattern where |
Hmm, I didn't think of that. I see three ways to solve this:
I'll make an issue for this since this pr is already useful as is. |
Fixes issue #3779 (I think?).