add is_exhaustive field to typeinfo

master
Vexu 2020-01-15 21:50:12 +02:00
parent f3d174aa61
commit c57784aa15
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
3 changed files with 8 additions and 1 deletions

View File

@ -253,6 +253,7 @@ pub const TypeInfo = union(enum) {
tag_type: type,
fields: []EnumField,
decls: []Declaration,
is_exhaustive: bool,
};
/// This data structure is used by the Zig language code generation and

View File

@ -23107,7 +23107,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
result->special = ConstValSpecialStatic;
result->type = ir_type_info_get_type(ira, "Enum", nullptr);
ZigValue **fields = alloc_const_vals_ptrs(4);
ZigValue **fields = alloc_const_vals_ptrs(5);
result->data.x_struct.fields = fields;
// layout: ContainerLayout
@ -23153,6 +23153,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
{
return err;
}
// is_exhaustive: bool
ensure_field_index(result->type, "is_exhaustive", 4);
fields[4]->special = ConstValSpecialStatic;
fields[4]->type = ira->codegen->builtin_types.entry_bool;
fields[4]->data.x_bool = !type_entry->data.enumeration.non_exhaustive;
break;
}

View File

@ -46,6 +46,7 @@ test "non-exhaustive enum" {
expect(@enumToInt(e) == 12);
e = @intToEnum(E, y);
expect(@enumToInt(e) == 52);
expect(@typeInfo(E).Enum.is_exhaustive == false);
}
};
S.doTheTest(52);