lang: tuple element assignment + named-tuple field names
Two fixes: - Element assignment `t.0 = v` (the known Phase-4.2 gap): the lvalue path looked the element up by NAME via getStructFields, never matched a tuple (positional), and left field_ty .unresolved -> ptr(.unresolved) -> codegen panic. Added a tuple branch to the field-assignment lowering that indexes by position (numeric) or name (tup.names), mirroring the read path. Fixes `c.sources.0 = v` on a generic-instance pack field too. - Named tuples: the parser dropped captured field names for a tuple TYPE `(x: T, y: U)` (passed field_names=null), and resolveTupleTypeWithBindings also nulled them. Both now preserve names (synthesizing _<i> for any unnamed slot), so `t.x` reads/writes by name and `.0` by position. examples/208. 243 examples + unit green.
This commit is contained in:
@@ -558,10 +558,20 @@ pub const Parser = struct {
|
||||
.call_conv = call_conv,
|
||||
} });
|
||||
}
|
||||
// No '->': tuple type (even for single element)
|
||||
// No '->': tuple type (even for single element). Keep field names
|
||||
// for a named tuple `(x: T, y: U)` so `t.x` resolves. `field_names`
|
||||
// is non-optional per slot, so synthesize `_<i>` for any unnamed one.
|
||||
var field_names: ?[]const []const u8 = null;
|
||||
if (has_names) {
|
||||
var fns = std.ArrayList([]const u8).empty;
|
||||
for (param_names.items, 0..) |pn, i| {
|
||||
try fns.append(self.allocator, pn orelse try std.fmt.allocPrint(self.allocator, "_{d}", .{i}));
|
||||
}
|
||||
field_names = try fns.toOwnedSlice(self.allocator);
|
||||
}
|
||||
return try self.createNode(start, .{ .tuple_type_expr = .{
|
||||
.field_types = try param_types.toOwnedSlice(self.allocator),
|
||||
.field_names = null,
|
||||
.field_names = field_names,
|
||||
} });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user