authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-17 10:59:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-17 10:59:40-07:00
log127cd06ba1c3406a41aecae01ca32162690ab4e1
tree294823fa0e71e7955862e2a709a32e9f571591cd
parentfdd11f6cee7ef14253cef53729e09d9415b4be7e

stage2: add haveFieldTypes() assertions

This will help with contributions such as #9966.

1 files changed, 3 insertions(+), 0 deletions(-)

src/type.zig+3
...@@ -2573,12 +2573,14 @@ pub const Type = extern union {...@@ -2573,12 +2573,14 @@ pub const Type = extern union {
25732573
2574 pub fn unionFields(ty: Type) Module.Union.Fields {2574 pub fn unionFields(ty: Type) Module.Union.Fields {
2575 const union_obj = ty.cast(Payload.Union).?.data;2575 const union_obj = ty.cast(Payload.Union).?.data;
2576 assert(union_obj.haveFieldTypes());
2576 return union_obj.fields;2577 return union_obj.fields;
2577 }2578 }
25782579
2579 pub fn unionFieldType(ty: Type, enum_tag: Value) Type {2580 pub fn unionFieldType(ty: Type, enum_tag: Value) Type {
2580 const union_obj = ty.cast(Payload.Union).?.data;2581 const union_obj = ty.cast(Payload.Union).?.data;
2581 const index = union_obj.tag_ty.enumTagFieldIndex(enum_tag).?;2582 const index = union_obj.tag_ty.enumTagFieldIndex(enum_tag).?;
2583 assert(union_obj.haveFieldTypes());
2582 return union_obj.fields.values()[index].ty;2584 return union_obj.fields.values()[index].ty;
2583 }2585 }
25842586
...@@ -3376,6 +3378,7 @@ pub const Type = extern union {...@@ -3376,6 +3378,7 @@ pub const Type = extern union {
3376 .empty_struct => return .{},3378 .empty_struct => return .{},
3377 .@"struct" => {3379 .@"struct" => {
3378 const struct_obj = ty.castTag(.@"struct").?.data;3380 const struct_obj = ty.castTag(.@"struct").?.data;
3381 assert(struct_obj.haveFieldTypes());
3379 return struct_obj.fields;3382 return struct_obj.fields;
3380 },3383 },
3381 else => unreachable,3384 else => unreachable,