You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
f-string: an empty format spec {x:} formats with precision 0 (prints nothing for a str) instead of the default display (§15.4.1) #1823
§15.4.1 Format Specification Grammar: spec := [[fill]align][sign]['#']['0'][width]['.' precision][mode] — "All fields are optional." {x:} is a spec with every field omitted, so it formats as {x}.
Repro
fn main:
let h = "hello"
print(f"[{h:}]")
let n = 42
print(f"[{n:}]")
Actual
With the n lines removed, the program prints [] — the str is formatted with precision 0. With them, check refuses a well-formed spec:
error: precision requires float or string type
7 | print(f"[{n:}]")
Same on the pinned seed, the installed compiler and the #1810 branch.
Cause
Parser.parse_format_spec_text (src/Parser.w, if slen == 0: return self.poisoned_expr()) turns an empty spec into a poisoned node without a diagnostic; the f-string lowering then reads that node as an NK_FSTRING_SPEC (SemaCheck.w ~8179 reads get_data2(spec_node) as the precision). A silent fallback: the program compiles and prints the wrong text.
Expected
[hello] and [42]: an empty spec builds the default spec node (fill space, no align, width 0, precision -1, no mode).
Found while building the #1810 matrix (a {h:} cell over a &str); not specific to &str.
Activity