aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorCody Tapscott <topolarity@tapscott.me>2022-07-08 15:09:56 -0700
committerCody Tapscott <topolarity@tapscott.me>2022-07-08 19:50:28 -0700
commit2fff25fd220632cc6943680d3d6bbb1f21fa141f (patch)
treec4d7be35ec022324c46761db643e2f28418cccb4 /src/type.zig
parent6f0807f50f4e946bb850e746beaa5d6556cf7750 (diff)
downloadzig-2fff25fd220632cc6943680d3d6bbb1f21fa141f.tar.gz
zig-2fff25fd220632cc6943680d3d6bbb1f21fa141f.zip
stage2: Support initializing anonymous struct type
This commit adds support for initializing `.anon_struct` types. There is also some follow-up work to do for both tuples and structs regarding comptime fields, so this also adds some tests to keep track of that work.
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index 9552d734ba..1de4dd5ae0 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -5432,6 +5432,24 @@ pub const Type = extern union {
}
}
+ pub fn structFieldDefaultValue(ty: Type, index: usize) Value {
+ switch (ty.tag()) {
+ .@"struct" => {
+ const struct_obj = ty.castTag(.@"struct").?.data;
+ return struct_obj.fields.values()[index].default_val;
+ },
+ .tuple => {
+ const tuple = ty.castTag(.tuple).?.data;
+ return tuple.values[index];
+ },
+ .anon_struct => {
+ const struct_obj = ty.castTag(.anon_struct).?.data;
+ return struct_obj.values[index];
+ },
+ else => unreachable,
+ }
+ }
+
pub fn structFieldValueComptime(ty: Type, index: usize) ?Value {
switch (ty.tag()) {
.@"struct" => {