| author | |
| committer | |
| log | 5c2238fc4ad1d10f0620c931d369005b53742eb7 |
| tree | 220fce9b5d4607c5c1c15994b50f1c3d37e54cc2 |
| parent | c57784aa15b50a9f38482154170924babab19c03 |
| signature |
* error for '_' prong on exhaustive enum
* todo panic for `@tagName` on non-exhaustive enum
* don't require '_' field on tagged unions3 files changed, 10 insertions(+), 2 deletions(-)
src/analyze.cpp+1-1| ... | ... | @@ -3293,7 +3293,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3293 | 3293 | } else if (enum_type_node != nullptr) { |
| 3294 | 3294 | for (uint32_t i = 0; i < tag_type->data.enumeration.src_field_count; i += 1) { |
| 3295 | 3295 | TypeEnumField *enum_field = &tag_type->data.enumeration.fields[i]; |
| 3296 | if (!covered_enum_fields[i]) { | |
| 3296 | if (!covered_enum_fields[i] && !buf_eql_str(enum_field->name, "_")) { | |
| 3297 | 3297 | AstNode *enum_decl_node = tag_type->data.enumeration.decl_node; |
| 3298 | 3298 | AstNode *field_node = enum_decl_node->data.container_decl.fields.at(i); |
| 3299 | 3299 | ErrorMsg *msg = add_node_error(g, decl_node, |
src/codegen.cpp+2| ... | ... | @@ -5065,6 +5065,8 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable |
| 5065 | 5065 | { |
| 5066 | 5066 | ZigType *enum_type = instruction->target->value->type; |
| 5067 | 5067 | assert(enum_type->id == ZigTypeIdEnum); |
| 5068 | if (enum_type->data.enumeration.non_exhaustive) | |
| 5069 | zig_panic("TODO @tagName on non-exhaustive enum"); | |
| 5068 | 5070 | |
| 5069 | 5071 | LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type); |
| 5070 | 5072 |
src/ir.cpp+7-1| ... | ... | @@ -22357,6 +22357,8 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns |
| 22357 | 22357 | if (instr_is_comptime(target)) { |
| 22358 | 22358 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) |
| 22359 | 22359 | return ira->codegen->invalid_instruction; |
| 22360 | if (target->value->type->data.enumeration.non_exhaustive) | |
| 22361 | zig_panic("TODO @tagName on non-exhaustive enum"); | |
| 22360 | 22362 | TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint); |
| 22361 | 22363 | ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; |
| 22362 | 22364 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| ... | ... | @@ -26471,7 +26473,11 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 26471 | 26473 | bigint_incr(&field_index); |
| 26472 | 26474 | } |
| 26473 | 26475 | } |
| 26474 | if (switch_type->data.enumeration.non_exhaustive && instruction->have_underscore_prong) { | |
| 26476 | if (instruction->have_underscore_prong) { | |
| 26477 | if (!switch_type->data.enumeration.non_exhaustive){ | |
| 26478 | ir_add_error(ira, &instruction->base, | |
| 26479 | buf_sprintf("switch on non-exhaustive enum has `_` prong")); | |
| 26480 | } | |
| 26475 | 26481 | for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) { |
| 26476 | 26482 | TypeEnumField *enum_field = &switch_type->data.enumeration.fields[i]; |
| 26477 | 26483 | if (buf_eql_str(enum_field->name, "_")) |