Commit c57784aa15

Vexu <git@vexu.eu>
2020-01-15 20:50:12
add is_exhaustive field to typeinfo
1 parent f3d174a
Changed files (3)
lib
src
test
stage1
behavior
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
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;
             }
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);