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.
This commit is contained in:
22
examples/0184-types-union-member-struct-literal-assign.sx
Normal file
22
examples/0184-types-union-member-struct-literal-assign.sx
Normal file
@@ -0,0 +1,22 @@
|
||||
// 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
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
code=9
|
||||
a=5
|
||||
Reference in New Issue
Block a user