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(...@@ -4134,7 +4134,7 @@ fn unionDeclInner(
4134 if (member.comptime_token) |comptime_token| {4134 if (member.comptime_token) |comptime_token| {
4135 return astgen.failTok(comptime_token, "union fields cannot be marked comptime", .{});4135 return astgen.failTok(comptime_token, "union fields cannot be marked comptime", .{});
4136 }4136 }
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
4139 const field_name = try astgen.identAsString(member.ast.name_token);4139 const field_name = try astgen.identAsString(member.ast.name_token);
4140 fields_data.appendAssumeCapacity(field_name);4140 fields_data.appendAssumeCapacity(field_name);
...@@ -4149,8 +4149,11 @@ fn unionDeclInner(...@@ -4149,8 +4149,11 @@ fn unionDeclInner(
4149 (@as(u32, @boolToInt(have_value)) << 30) |4149 (@as(u32, @boolToInt(have_value)) << 30) |
4150 (@as(u32, @boolToInt(unused)) << 31);4150 (@as(u32, @boolToInt(unused)) << 31);
41514151
4152 if (have_type and node_tags[member.ast.type_expr] != .@"anytype") {4152 if (have_type) {
4153 const field_type = try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);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);
4154 fields_data.appendAssumeCapacity(@enumToInt(field_type));4157 fields_data.appendAssumeCapacity(@enumToInt(field_type));
4155 }4158 }
4156 if (have_align) {4159 if (have_align) {
src/Sema.zig+3-1
...@@ -12629,8 +12629,10 @@ fn semaUnionFields(...@@ -12629,8 +12629,10 @@ fn semaUnionFields(
12629 set.putAssumeCapacity(field_name, {});12629 set.putAssumeCapacity(field_name, {});
12630 }12630 }
1263112631
12632 const field_ty: Type = if (field_type_ref == .none)12632 const field_ty: Type = if (!has_type)
12633 Type.initTag(.void)12633 Type.initTag(.void)
12634 else if (field_type_ref == .none)
12635 Type.initTag(.noreturn)
12634 else12636 else
12635 // TODO: if we need to report an error here, use a source location12637 // TODO: if we need to report an error here, use a source location
12636 // that points to this type expression rather than the union.12638 // that points to this type expression rather than the union.
src/Zir.zig+1
...@@ -2686,6 +2686,7 @@ pub const Inst = struct {...@@ -2686,6 +2686,7 @@ pub const Inst = struct {
2686 /// 9. fields: { // for every fields_len2686 /// 9. fields: { // for every fields_len
2687 /// field_name: u32, // null terminated string index2687 /// field_name: u32, // null terminated string index
2688 /// field_type: Ref, // if corresponding bit is set2688 /// field_type: Ref, // if corresponding bit is set
2689 /// - if none, means `anytype`.
2689 /// align: Ref, // if corresponding bit is set2690 /// align: Ref, // if corresponding bit is set
2690 /// tag_value: Ref, // if corresponding bit is set2691 /// tag_value: Ref, // if corresponding bit is set
2691 /// }2692 /// }