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
[value; N] with a const (or any non-literal) N builds a 1-element array: the parser's fill desugar silently uses count 1 (§4.3a) #1478
Found while fixing #1358 (the ast dump renders the desugared fill).
Spec §4.3a Fixed-Size Arrays: "[value; N] repeat: array of N copies of value" and "Length N must be a compile-time constant (integer literal or const)."
Parser.w (the // Array fill: [value; N] branch, ~line 7563) desugars the fill at parse time into an NK_ARRAY_LIT with N copies of the element node, but it evaluates N only when the count is an NK_INT_LIT; for anything else it falls back to fill_count = 1 with no diagnostic:
var fill_count = 0
if self.pool.kind(count_expr) == NodeKind.NK_INT_LIT:
...
if fill_count <= 0:
fill_count = 1
Repro (installed v0.15.2.1):
let N: i64 = 4
fn main:
let a = [7 as i32; N]
print(f"{a.len()}") // expect 4, prints 1
let b: [4]i32 = [7 as i32; N]
print(f"{b.len()} {b[3]}") // expect "4 7", prints "4 0"
[7 as i32; 2 + 2] also has length 1. The typed binding compiles and reads uninitialized/zeroed tail elements: silent wrong code (CLAUDE.md "No Silent Fallbacks").
Related cost: the same desugar stores N element ids in the AST extra table, so var the_cache: [16777216]u8 = [0 as u8; 16777216] (lib/std/tommyds/check_.w) adds 16,777,216 extras (64 MiB) at parse time and every phase that walks the literal walks 16M elements. A fill should stay one node (element + count expression) resolved by Sema, which also gives the const case a place to be evaluated or refused loudly.
Expected: [v; N] with a const N builds N copies; a count that is not a compile-time constant is a compile error naming it.
Activity
with ast: builds its dump in one buffer per list and prints a fill as…
Sema cluster A: #1344 #1472 #1493 #1494 #1303 #1477 #1503 #1502 #1517 #…
Parser/Sema/MirLower: `[value; N]` with a `const` count builds N copi…
Sema: a `[v; N]` count is a compile-time constant expression (§9.1b) …
Parser/Sema/MirLower: `[value; N]` with a `const` count builds N copi…
Sema: a `[v; N]` count is a compile-time constant expression (§9.1b) …
Parser/Sema/MirLower: `[value; N]` with a `const` count builds N copi…
Sema: a `[v; N]` count is a compile-time constant expression (§9.1b) …
Spec v7.7 (D75): once parameters, fills, distinct casts, payload disc…