mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 05:20:34 +00:00
stage2: fix astgen for anytype union fields and differentiate anytype vs inferred void in semaUnionFields
This commit is contained in:
parent
8e1aa72c69
commit
784be05a1a
@ -4134,7 +4134,7 @@ fn unionDeclInner(
|
||||
if (member.comptime_token) |comptime_token| {
|
||||
return astgen.failTok(comptime_token, "union fields cannot be marked comptime", .{});
|
||||
}
|
||||
try fields_data.ensureUnusedCapacity(gpa, if (node_tags[member.ast.type_expr] != .@"anytype") 4 else 3);
|
||||
try fields_data.ensureUnusedCapacity(gpa, 4);
|
||||
|
||||
const field_name = try astgen.identAsString(member.ast.name_token);
|
||||
fields_data.appendAssumeCapacity(field_name);
|
||||
@ -4149,8 +4149,11 @@ fn unionDeclInner(
|
||||
(@as(u32, @boolToInt(have_value)) << 30) |
|
||||
(@as(u32, @boolToInt(unused)) << 31);
|
||||
|
||||
if (have_type and node_tags[member.ast.type_expr] != .@"anytype") {
|
||||
const field_type = try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
|
||||
if (have_type) {
|
||||
const field_type: Zir.Inst.Ref = if (node_tags[member.ast.type_expr] == .@"anytype")
|
||||
.none
|
||||
else
|
||||
try typeExpr(&block_scope, &namespace.base, member.ast.type_expr);
|
||||
fields_data.appendAssumeCapacity(@enumToInt(field_type));
|
||||
}
|
||||
if (have_align) {
|
||||
|
||||
@ -12629,8 +12629,10 @@ fn semaUnionFields(
|
||||
set.putAssumeCapacity(field_name, {});
|
||||
}
|
||||
|
||||
const field_ty: Type = if (field_type_ref == .none)
|
||||
const field_ty: Type = if (!has_type)
|
||||
Type.initTag(.void)
|
||||
else if (field_type_ref == .none)
|
||||
Type.initTag(.noreturn)
|
||||
else
|
||||
// TODO: if we need to report an error here, use a source location
|
||||
// that points to this type expression rather than the union.
|
||||
|
||||
@ -2686,6 +2686,7 @@ pub const Inst = struct {
|
||||
/// 9. fields: { // for every fields_len
|
||||
/// field_name: u32, // null terminated string index
|
||||
/// field_type: Ref, // if corresponding bit is set
|
||||
/// - if none, means `anytype`.
|
||||
/// align: Ref, // if corresponding bit is set
|
||||
/// tag_value: Ref, // if corresponding bit is set
|
||||
/// }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user