diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index dbd19fbadf..4b80b38100 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -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 diff --git a/src/ir.cpp b/src/ir.cpp index 6876214510..08f80e0647 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -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; } diff --git a/test/stage1/behavior/enum.zig b/test/stage1/behavior/enum.zig index c888722f27..82e57a3a38 100644 --- a/test/stage1/behavior/enum.zig +++ b/test/stage1/behavior/enum.zig @@ -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);