authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-01-15 21:50:12+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-01-15 21:50:12+02:00
logc57784aa15b50a9f38482154170924babab19c03
tree3a916fef243637252ce22f08e34e30cd0eb37020
parentf3d174aa616401117927988dfc499a1762db01a3
signature Commit is signed but in an unrecognized format.

add is_exhaustive field to typeinfo


3 files changed, 8 insertions(+), 1 deletions(-)

lib/std/builtin.zig+1
......@@ -253,6 +253,7 @@ pub const TypeInfo = union(enum) {
253253 tag_type: type,
254254 fields: []EnumField,
255255 decls: []Declaration,
256 is_exhaustive: bool,
256257 };
257258
258259 /// This data structure is used by the Zig language code generation and
src/ir.cpp+6-1
......@@ -23107,7 +23107,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2310723107 result->special = ConstValSpecialStatic;
2310823108 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
2310923109
23110 ZigValue **fields = alloc_const_vals_ptrs(4);
23110 ZigValue **fields = alloc_const_vals_ptrs(5);
2311123111 result->data.x_struct.fields = fields;
2311223112
2311323113 // layout: ContainerLayout
......@@ -23153,6 +23153,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2315323153 {
2315423154 return err;
2315523155 }
23156 // is_exhaustive: bool
23157 ensure_field_index(result->type, "is_exhaustive", 4);
23158 fields[4]->special = ConstValSpecialStatic;
23159 fields[4]->type = ira->codegen->builtin_types.entry_bool;
23160 fields[4]->data.x_bool = !type_entry->data.enumeration.non_exhaustive;
2315623161
2315723162 break;
2315823163 }
test/stage1/behavior/enum.zig+1
......@@ -46,6 +46,7 @@ test "non-exhaustive enum" {
4646 expect(@enumToInt(e) == 12);
4747 e = @intToEnum(E, y);
4848 expect(@enumToInt(e) == 52);
49 expect(@typeInfo(E).Enum.is_exhaustive == false);
4950 }
5051 };
5152 S.doTheTest(52);