Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.2k
Assert compile error for unspecified array/slice format #7675
Copy link
Copy link
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
I'm opening an issue based on my comment here: #6870 (comment)
That PR was just merged which means that now the default format for printing slices/arrays will be integer values rather than raw values, i.e.:
The fix for this example is to specify
{s}whenever you're printing a string. The problem with this is now whenever a format string does not specify the correct format, the bug will not be caught until runtime and the string is inspected. What makes this worse is that this kind of format string is commonly used for error messages, which often don't get tested or inspected until the error occurs, which many times is only seen rarely if at all. There is now a disconnect between what code looks like, and the default way to format strings.To remedy this, I propose that we require a format specifier for slices/arrays. On top of that, in order to support generic code I propose that we enable today's current behavior of
{}with an explicit specifier. Something like{any}. The{any}specifier would mean "print this thing, I'm not picky about the exact format, just print it somehow". The difference here is that instead having this "I'm not picky about the format" attitude by default with{}, the user has to opt-in to it.Also note that with the PR that was just merged, alot of Zig code will now be broken due to missing format specifiers that were meant to be
{s}. Implementing this proposal means these bugs will be found at compile-time so they will be easy to find and fix.Here's the list of array specifiers: