Skip to content

f-string width/align/precision on a bool, enum, struct or collection interpolant formats garbage (FMT_BUF_WRITE_FMT treats every non-numeric value as str) #1565

Closed

Description

@ehartford

Found while implementing D61 (#1480); predates it.

validate_fstring_spec rejects mode/type mismatches ({p:x}), but a width or alignment with no mode passes for any type: {flag:>5}, {opt:<10}, {point:>8}, {vec:>4}. Codegen (gen_fmt_buf_write_fmt, gen_fmt_with_spec) handles integer and float LLVM values and treats everything else as a str header (build_str_ref_from_value(val)), so a bool prints 1/0 and an enum or struct is read as a str header — garbage, not a diagnostic. §15.4.6 says only ? mode and width/alignment are valid on bool; the spec does not say what width means for an enum or aggregate.

Expected: Sema rejects width/align/precision on types that have no display (or defines them), and bool with width pads true/false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions