authorgravatar for matthew.h.borkowski@gmail.comMatthew Borkowski <matthew.h.borkowski@gmail.com> 2021-10-09 18:16:43-04:00
committergravatar for matthew.h.borkowski@gmail.comMatthew Borkowski <matthew.h.borkowski@gmail.com> 2021-10-09 20:39:39-04:00
log784be05a1abd94da96cce7c6381395f4f7b1ab5f
tree1cac2ca458721ce98f5566cd39b57f07291f0396
parent8e1aa72c69cddc9fcd0bd8a3f9f4e9d3a8d002af

stage2: fix astgen for anytype union fields and differentiate anytype vs inferred void in semaUnionFields


3 files changed, 10 insertions(+), 4 deletions(-)

src/AstGen.zig+6-3
......@@ -4134,7 +4134,7 @@ fn unionDeclInner(
41344134 if (member.comptime_token) |comptime_token| {
41354135 return astgen.failTok(comptime_token, "union fields cannot be marked comptime", .{});
41364136 }
4137 try fields_data.ensureUnusedCapacity(gpa, if (node_tags[member.ast.type_expr] != .@"anytype") 4 else 3);
4137 try fields_data.ensureUnusedCapacity(gpa, 4);
41384138
41394139 const field_name = try astgen.identAsString(member.ast.name_token);
41404140 fields_data.appendAssumeCapacity(field_name);
......@@ -4149,8 +4149,11 @@ fn unionDeclInner(
41494149 (@as(u32, @boolToInt(have_value)) << 30) |
41504150 (@as(u32, @boolToInt(unused)) << 31);
41514151
4152 if (have_type and node_tags[member.ast.type_expr] != .@"anytype") {
4153 const field_type = try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
4152 if (have_type) {
4153 const field_type: Zir.Inst.Ref = if (node_tags[member.ast.type_expr] == .@"anytype")
4154 .none
4155 else
4156 try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
41544157 fields_data.appendAssumeCapacity(@enumToInt(field_type));
41554158 }
41564159 if (have_align) {
src/Sema.zig+3-1
......@@ -12629,8 +12629,10 @@ fn semaUnionFields(
1262912629 set.putAssumeCapacity(field_name, {});
1263012630 }
1263112631
12632 const field_ty: Type = if (field_type_ref == .none)
12632 const field_ty: Type = if (!has_type)
1263312633 Type.initTag(.void)
12634 else if (field_type_ref == .none)
12635 Type.initTag(.noreturn)
1263412636 else
1263512637 // TODO: if we need to report an error here, use a source location
1263612638 // that points to this type expression rather than the union.
src/Zir.zig+1
......@@ -2686,6 +2686,7 @@ pub const Inst = struct {
26862686 /// 9. fields: { // for every fields_len
26872687 /// field_name: u32, // null terminated string index
26882688 /// field_type: Ref, // if corresponding bit is set
2689 /// - if none, means `anytype`.
26892690 /// align: Ref, // if corresponding bit is set
26902691 /// tag_value: Ref, // if corresponding bit is set
26912692 /// }