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.
22 lines
857 B
Plaintext
22 lines
857 B
Plaintext
// Writing through a nested struct field lvalue (`outer.inner.x = v`) and taking
|
|
// the address of a valid field both resolve the field pointer correctly: the
|
|
// lvalue-pointer path (lowerExprAsPtr) GEPs the matched field, never a silent
|
|
// field-0 default. Positive companion to the missing-field diagnostic (1145).
|
|
#import "modules/std.sx";
|
|
|
|
Inner :: struct { a: s64; b: s64; }
|
|
Outer :: struct { inner: Inner; tag: s64; }
|
|
|
|
bump :: (p: *s64) { p.* = p.* + 100; }
|
|
|
|
main :: () {
|
|
o := Outer.{ inner = Inner.{ a = 1, b = 2 }, tag = 9 };
|
|
o.inner.a = 11; // nested struct field store via lowerExprAsPtr
|
|
o.inner.b = 22;
|
|
o.tag = 33; // direct struct field store
|
|
print("a={} b={} tag={}\n", o.inner.a, o.inner.b, o.tag);
|
|
|
|
bump(@o.inner.a); // address-of a matched nested field
|
|
print("a2={}\n", o.inner.a);
|
|
}
|