diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index dbd19fbadf2a17f4b285a52fa83c50dd3702421c..4b80b381007ef5fdb9748ed9c27dfbb25bb0bcb0 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 6876214510a8d7875bdef981bc287f8ebcfc3371..08f80e064758ad4e7dcfec3ffaf6f5e8f7b3d24f 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 c888722f27df9cf10fed6f6c56e6872f7a277b5e..82e57a3a38951fd48f46defb9f367f3a72a5e027 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);