stage1: Fix constant folding of single-element enums
Fill in the correct value instead of leaving everything uninitialized. This problem can be noticed in behavior/union.zig but it's masked by some other "optimization" kicking in at the wrong time, the following commits will address that.
This commit is contained in:
parent
b6b7a6401c
commit
865d6df03e
@ -6122,6 +6122,11 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
|
|||||||
result->data.x_ptr.mut = ConstPtrMutComptimeConst;
|
result->data.x_ptr.mut = ConstPtrMutComptimeConst;
|
||||||
result->data.x_ptr.special = ConstPtrSpecialRef;
|
result->data.x_ptr.special = ConstPtrSpecialRef;
|
||||||
result->data.x_ptr.data.ref.pointee = get_the_one_possible_value(g, result->type->data.pointer.child_type);
|
result->data.x_ptr.data.ref.pointee = get_the_one_possible_value(g, result->type->data.pointer.child_type);
|
||||||
|
} else if (result->type->id == ZigTypeIdEnum) {
|
||||||
|
ZigType *enum_type = result->type;
|
||||||
|
assert(enum_type->data.enumeration.src_field_count == 1);
|
||||||
|
TypeEnumField *only_field = &result->type->data.enumeration.fields[0];
|
||||||
|
bigint_init_bigint(&result->data.x_enum_tag, &only_field->value);
|
||||||
}
|
}
|
||||||
g->one_possible_values.put(type_entry, result);
|
g->one_possible_values.put(type_entry, result);
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user