aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-12-17 00:31:32 +0100
committerAndrew Kelley <andrew@ziglang.org>2019-12-17 15:45:22 -0500
commitd8499f7abe43ec641027eb7f94b41906c9bf5cca (patch)
tree913014c0990e942c569fad7e67b2f9a701e1be09 /src/analyze.cpp
parentf389e5e61fcbc92423c16ccd2d0c79878d1589e4 (diff)
downloadzig-d8499f7abe43ec641027eb7f94b41906c9bf5cca.tar.gz
zig-d8499f7abe43ec641027eb7f94b41906c9bf5cca.zip
Make sure the fields array is always non-null
Fixes #3497
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 3318d4b9bb..fb677de0ee 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -5584,6 +5584,18 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
ZigValue *result = create_const_vals(1);
result->type = type_entry;
result->special = ConstValSpecialStatic;
+ if (result->type->id == ZigTypeIdStruct) {
+ // The fields array cannot be left unpopulated
+ const ZigType *struct_type = result->type;
+ const size_t field_count = struct_type->data.structure.src_field_count;
+ result->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
+ for (size_t i = 0; i < field_count; i += 1) {
+ TypeStructField *field = struct_type->data.structure.fields[i];
+ ZigType *field_type = resolve_struct_field_type(g, field);
+ assert(field_type != nullptr);
+ result->data.x_struct.fields[i] = get_the_one_possible_value(g, field_type);
+ }
+ }
g->one_possible_values.put(type_entry, result);
return result;
}