Files
sx/examples/0184-types-union-member-struct-literal-assign.sx
agra 4d32a4d4fb fix: propagate union-member type to a struct-literal RHS
Assigning a struct literal to a named-struct member of a plain union
(`u.b = .{ ... }`) lowered the RHS as .unresolved and tripped the
LLVM-emission tripwire: lowerAssignment's .field_access target-type
path used getStructFields, which returns nothing for a union, so the
literal never received its target type.

Unify the lvalue field matcher into a pure fieldLvalueResolve consumed
by both fieldLvaluePtr (GEP builder) and the target-type path, so the
store slot and the RHS target type can't diverge (covers union direct +
promoted members, tuple/vector lanes, and structs).

Resolves issue 0133 (depended on 0135). Regression test: examples/0184.
Notes the now end-to-end union path in issue 0132.
2026-06-13 18:55:41 +03:00

23 lines
803 B
Plaintext

// Assigning a struct LITERAL to a named-struct member of a plain `union`.
// `u.b = .{ code = 9 }` types the literal as the union member's struct type
// `S` and stores it — the target type propagates to a union-member lvalue
// exactly as it does to a struct field.
//
// Regression (issue 0133): the literal used to lower as `.unresolved` (the
// target-type path only inspected struct fields, not union members) and trip
// the LLVM-emission tripwire in emitStructInit.
#import "modules/std.sx";
S :: struct { code: i64; }
U :: union { a: i64; b: S; }
main :: () {
u : U = ---;
u.b = .{ code = 9 }; // union member <- struct literal
print("code={}\n", u.b.code); // 9
u.a = 5; // scalar member still works
print("a={}\n", u.a); // 5
}