Skip to content

hint optional format statement for optional values #24198

Open
@cameronmore

Description

@cameronmore

Zig Version

0.14.1

Steps to Reproduce and Observed Output

(I apologize in advance if this issue is not well written or is not substantive)

I’ve got a struct type with the following field:

programName: ?[]const u8 = null

And I could not figure out why my other fields like

otherField: []const u8, 

were printing when I formatted them as {s} but programName could only be formatted as {any}, and even then it only printed out the u8 value and not the string. I googled to find that the answer was to format optional values as {?s}. Maybe it says something in the documentation, but a compiler hint would have been helpful.

Expected Output

when detecting that a user is trying to format an optional field, it should hint to format as {?s} rather than the current message as {any} or {!}

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions