fix: literal element typing — typed-array null element, tuple coercion, positional var element (0173-0175)

0173: resolveArrayLiteralType gained no arm for [N]T/[]T heads, so a
([2]?i64).[...] head lost its ?i64 element type and a bare null reached
LLVM as const_null(.unresolved). Route structural heads through
resolveTypeWithBindings; validate an undefined element name in the head
via UnknownTypeChecker (semantic_diagnostics.zig) instead of a silent
empty-struct stub (no-silent-fallback).

0174: positional .{...} against a TUPLE target now coerces each element
to TupleInfo.fields[i] (was neither struct nor array, so uncoerced).

0175: a positional struct literal with a bare-variable element was
misclassified as a named shorthand (parser puns .{x} -> x=x), zeroing
the fields. has_names now consults the struct definition to reclassify a
punned non-field name as positional; positional coercion uses the
lowered value's real getRefType.

Regressions: optionals/0914, types/0199, types/0200, diagnostics/1196.
Verified by 4 adversarial reviews; suite 784/0. Filed adjacent bug 0176
(protocol-typed struct field method call aborts).
This commit is contained in:
agra
2026-06-23 00:25:28 +03:00
parent 5a436eddb1
commit 28bb101a4a
22 changed files with 369 additions and 11 deletions

View File

@@ -1,5 +1,17 @@
# 0175 — positional struct literal with a VARIABLE element silently zeroes the field
> **RESOLVED.** Root cause was named-vs-positional misclassification: the parser
> PUNS a bare-ident element `.{ x, … }` into a named field `x = x` (the legit
> `Vec4.{ w, z }` shorthand), so a positional-with-variable literal arrived as a
> spurious "named" literal and the named branch left every field at its default.
> Fix (`src/ir/lower/expr.zig`): `has_names` now consults the struct definition —
> a punned bare-ident whose name matches no declared field reclassifies the whole
> literal as positional; positional field coercion now uses the lowered value's
> actual `getRefType` (not a re-inferred `src_ty`) and steers per-field
> `target_type`. Legit shorthand, named, mixed, generic, forward-ref, and nested
> cases all verified unbroken by 4 adversarial reviews. Regression:
> `examples/types/0200-types-positional-struct-literal-variable-element.sx`.
## Symptom
A positional struct literal `S.{ x, ... }` whose element is a VARIABLE reference