aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorCody Tapscott <topolarity@tapscott.me>2022-07-07 12:28:51 -0700
committerVeikka Tuominen <git@vexu.eu>2022-07-08 10:19:17 +0300
commit33a39c4b2b8a597c7d40d0c3ea0f5ca12a4636a8 (patch)
treeeff4a0dd90e734758cb30c7440ba1b392bc2daec /src/type.zig
parent3a03872af76652515e467c1f33d918ead2c0a6b0 (diff)
downloadzig-33a39c4b2b8a597c7d40d0c3ea0f5ca12a4636a8.tar.gz
zig-33a39c4b2b8a597c7d40d0c3ea0f5ca12a4636a8.zip
stage2: Fix panic when printing AIR for tuple/anon struct types
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index 55466efe4a..9552d734ba 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -5372,6 +5372,18 @@ pub const Type = extern union {
}
}
+ pub fn structFieldName(ty: Type, field_index: usize) []const u8 {
+ switch (ty.tag()) {
+ .@"struct" => {
+ const struct_obj = ty.castTag(.@"struct").?.data;
+ assert(struct_obj.haveFieldTypes());
+ return struct_obj.fields.keys()[field_index];
+ },
+ .anon_struct => return ty.castTag(.anon_struct).?.data.names[field_index],
+ else => unreachable,
+ }
+ }
+
pub fn structFieldCount(ty: Type) usize {
switch (ty.tag()) {
.@"struct" => {