aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-04-05 17:09:01 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-04-05 17:09:01 -0400
commite2dc63644ab3d8e5cdaec2d58dc57c587295081f (patch)
tree776b9916ec8911cee97f7992e7255acf6331fc70 /src/analyze.cpp
parent6ef15fc8d00c06bc767b91515e2c919448948e6f (diff)
downloadzig-e2dc63644ab3d8e5cdaec2d58dc57c587295081f.tar.gz
zig-e2dc63644ab3d8e5cdaec2d58dc57c587295081f.zip
type_has_one_possible_value takes comptime struct fields into account
Before, type_has_one_possible_value would return false for the value `.{1}`. But actually, that type is a tuple with a single comptime field. Such a type, in fact, has one possible value. This plus the corresponding adjustment to get_the_one_possible_value solves #3878.
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index e627eaf91b..14b9c25c07 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -5769,6 +5769,10 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
type_entry->one_possible_value = OnePossibleValueNo;
for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
TypeStructField *field = type_entry->data.structure.fields[i];
+ if (field->is_comptime) {
+ // If this field is comptime then the field can only be one possible value
+ continue;
+ }
OnePossibleValue opv = (field->type_entry != nullptr) ?
type_has_one_possible_value(g, field->type_entry) :
type_val_resolve_has_one_possible_value(g, field->type_val);
@@ -5825,6 +5829,10 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
result->data.x_struct.fields = alloc_const_vals_ptrs(g, field_count);
for (size_t i = 0; i < field_count; i += 1) {
TypeStructField *field = struct_type->data.structure.fields[i];
+ if (field->is_comptime) {
+ copy_const_val(g, result->data.x_struct.fields[i], field->init_val);
+ continue;
+ }
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);