diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-01-17 14:26:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-17 14:26:12 -0500 |
| commit | b5ac079f88e9098ea9c95356518820a5c3fb42a8 (patch) | |
| tree | e4028947b688f53a5387b6b3e0b454090ee240dc /src/codegen.cpp | |
| parent | d9be6e5dc693fcbcb5f4c343a3d2b0b9fc786e25 (diff) | |
| parent | 39f92a9ee4ea109628e1f7d5a65bb53575e53194 (diff) | |
| download | zig-b5ac079f88e9098ea9c95356518820a5c3fb42a8.tar.gz zig-b5ac079f88e9098ea9c95356518820a5c3fb42a8.zip | |
Merge pull request #4191 from Vexu/non-exhaustive-enums
Implement non-exhaustive enums
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index cd009b3bea..3d4d2a8c31 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3356,7 +3356,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, LLVMValueRef tag_int_value = gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), instruction->target->value->type, tag_int_type, target_val); - if (ir_want_runtime_safety(g, &instruction->base) && wanted_type->data.enumeration.layout != ContainerLayoutExtern) { + if (ir_want_runtime_safety(g, &instruction->base) && !wanted_type->data.enumeration.non_exhaustive) { LLVMBasicBlockRef bad_value_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadValue"); LLVMBasicBlockRef ok_value_block = LLVMAppendBasicBlock(g->cur_fn_val, "OkValue"); size_t field_count = wanted_type->data.enumeration.src_field_count; @@ -5065,6 +5065,11 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable { ZigType *enum_type = instruction->target->value->type; assert(enum_type->id == ZigTypeIdEnum); + if (enum_type->data.enumeration.non_exhaustive) { + add_node_error(g, instruction->base.source_node, + buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991")); + codegen_report_errors_and_exit(g); + } LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type); |
