fix(ir): missing-field multi-assign + promoted-union-member lvalue [F0.10]
Completes the issue-0094 fix. attempt-1 made single-assign and address-of diagnose a missing struct field; the stress-review found two remaining defects in that change: 1. lowerMultiAssign's `.field_access` target kept the pre-fix shape — a struct-only loop that defaulted `field_idx 0` / `field_ty .unresolved` on a miss, then built the GEP and stored unconditionally. A missing field (`p.q, y = 2, 3`) silently wrote field 0 (printed `x=2 y=3`, no diagnostic), and a valid promoted-union / tuple member at a non-zero offset corrupted field 0 instead of its own slot. 2. attempt-1's new union branch in lowerExprAsPtr resolved only DIRECT union field names, so `@v.x` on a promoted anonymous-struct member reported "field 'x' not found on type 'Vec2'" even though `v.x = 41` worked. Both lvalue-pointer sites and the multi-assign store now route through one shared resolver, `fieldLvaluePtr`, that handles struct fields, union direct fields, promoted anonymous-struct union members, and tuple elements, and returns null (no field-0 / `.unresolved` default) on a genuine miss. Each caller emits the read path's `emitFieldError` on null. This collapses the three previously-divergent field-lvalue walks into one, fixing the multi-assign missing-field corruption, the promoted-member over-rejection, and (as a side effect of correct resolution) non-zero-offset promoted-union and tuple multi-assign stores. The types.zig tripwire is untouched. Regression tests: - examples/1145 extended: multi-assign missing field (`p.r, y`) errors, exit 1. - examples/0166 (new): promoted union member written and address-of'd, including a non-zero-offset member (`@v.y`), compiles and runs. - src/ir/lower.test.zig: multi-assign missing-field field-not-found unit test.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
x=42
|
||||
y=101
|
||||
@@ -1,11 +1,17 @@
|
||||
error: field 'q' not found on type 'Point'
|
||||
--> examples/1145-diagnostics-missing-struct-field-assign.sx:18:5
|
||||
--> examples/1145-diagnostics-missing-struct-field-assign.sx:20:5
|
||||
|
|
||||
18 | p.q = 2; // site 1: lowerAssignment target path
|
||||
20 | p.q = 2; // site 1: lowerAssignment target path
|
||||
| ^^^
|
||||
|
||||
error: field 'missing' not found on type 'Outer'
|
||||
--> examples/1145-diagnostics-missing-struct-field-assign.sx:21:5
|
||||
--> examples/1145-diagnostics-missing-struct-field-assign.sx:23:5
|
||||
|
|
||||
21 | o.missing.a = 5; // site 2: lowerExprAsPtr fallback
|
||||
23 | o.missing.a = 5; // site 2: lowerExprAsPtr fallback
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: field 'r' not found on type 'Point'
|
||||
--> examples/1145-diagnostics-missing-struct-field-assign.sx:26:5
|
||||
|
|
||||
26 | p.r, y = 3, 4; // site 3: lowerMultiAssign field path
|
||||
| ^^^
|
||||
|
||||
Reference in New Issue
Block a user