fix(ir): missing struct field assignment errors cleanly, no LLVM panic [F0.10]

Assigning to a nonexistent struct field (`p.q = 2` where Point has no `q`)
aborted the compiler with the `.unresolved` LLVM tripwire instead of a source
diagnostic (issue 0094). The lvalue field lookup never diagnosed a miss:

- `lowerAssignment`'s `.field_access` target left `field_ty = .unresolved` when
  no struct field matched, then built `ptrTo(field_ty)` and stored — so a
  pointer-to-`.unresolved` reached LLVM emission and tripped the panic.
- `lowerExprAsPtr`'s `.field_access` fallback returned
  `structGepTyped(obj_ptr, 0, .s64, obj_ty)` on a miss — a silent field-0/`.s64`
  default that mislowered the lvalue.

Both sites now reuse the read path's `emitFieldError` (the exact facility
`lowerFieldAccessOnType` uses), so read and write reject identically with
`field 'q' not found on type 'Point'`. `lowerExprAsPtr` also resolves
union/tagged-union fields via `union_gep` (the old `.s64` fallback was silently
standing in for union field access — e.g. `u.a[0] = v`), so that path is fixed,
not just made loud. The `types.zig` tripwire is untouched: the fix is to never
produce `.unresolved` for a missing-field store.

Regression tests:
- examples/1145-diagnostics-missing-struct-field-assign.sx — negative, both
  sites error, exit 1.
- examples/0165-types-nested-struct-field-assign.sx — positive, nested struct
  field write + address-of a matched field still work.
- src/ir/lower.test.zig — lowering unit test asserting the field-not-found
  diagnostic for a missing-field assignment.
This commit is contained in:
agra
2026-06-05 13:24:15 +03:00
parent 22c2e60efc
commit e13518e8aa
11 changed files with 210 additions and 2 deletions

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1,2 @@
a=11 b=22 tag=33
a2=111

View File

@@ -0,0 +1,11 @@
error: field 'q' not found on type 'Point'
--> examples/1145-diagnostics-missing-struct-field-assign.sx:18:5
|
18 | 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
|
21 | o.missing.a = 5; // site 2: lowerExprAsPtr fallback
| ^^^^^^^^^