From 5c2238fc4ad1d10f0620c931d369005b53742eb7 Mon Sep 17 00:00:00 2001 From: Vexu Date: Wed, 15 Jan 2020 22:09:19 +0200 Subject: [PATCH] small fixes * error for '_' prong on exhaustive enum * todo panic for `@tagName` on non-exhaustive enum * don't require '_' field on tagged unions --- src/analyze.cpp | 2 +- src/codegen.cpp | 2 ++ src/ir.cpp | 8 +++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index 0b2b6ddea..7669e0890 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3293,7 +3293,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { } else if (enum_type_node != nullptr) { for (uint32_t i = 0; i < tag_type->data.enumeration.src_field_count; i += 1) { TypeEnumField *enum_field = &tag_type->data.enumeration.fields[i]; - if (!covered_enum_fields[i]) { + if (!covered_enum_fields[i] && !buf_eql_str(enum_field->name, "_")) { AstNode *enum_decl_node = tag_type->data.enumeration.decl_node; AstNode *field_node = enum_decl_node->data.container_decl.fields.at(i); ErrorMsg *msg = add_node_error(g, decl_node, diff --git a/src/codegen.cpp b/src/codegen.cpp index 0dc820be5..42fd18882 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5065,6 +5065,8 @@ 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) + zig_panic("TODO @tagName on non-exhaustive enum"); LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type); diff --git a/src/ir.cpp b/src/ir.cpp index 08f80e064..7aa3243c3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -22357,6 +22357,8 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns if (instr_is_comptime(target)) { if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) return ira->codegen->invalid_instruction; + if (target->value->type->data.enumeration.non_exhaustive) + zig_panic("TODO @tagName on non-exhaustive enum"); TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint); ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; IrInstruction *result = ir_const(ira, &instruction->base, nullptr); @@ -26471,7 +26473,11 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, bigint_incr(&field_index); } } - if (switch_type->data.enumeration.non_exhaustive && instruction->have_underscore_prong) { + if (instruction->have_underscore_prong) { + if (!switch_type->data.enumeration.non_exhaustive){ + ir_add_error(ira, &instruction->base, + buf_sprintf("switch on non-exhaustive enum has `_` prong")); + } for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) { TypeEnumField *enum_field = &switch_type->data.enumeration.fields[i]; if (buf_eql_str(enum_field->name, "_"))