authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-01-15 22:09:19+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-01-15 22:09:19+02:00
log5c2238fc4ad1d10f0620c931d369005b53742eb7
tree220fce9b5d4607c5c1c15994b50f1c3d37e54cc2
parentc57784aa15b50a9f38482154170924babab19c03
signaturelock-open Commit is signed but in an unrecognized format.

small fixes

* error for '_' prong on exhaustive enum * todo panic for `@tagName` on non-exhaustive enum * don't require '_' field on tagged unions

3 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) {
32933293 } else if (enum_type_node != nullptr) {
32943294 for (uint32_t i = 0; i < tag_type->data.enumeration.src_field_count; i += 1) {
32953295 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, "_")) {
32973297 AstNode *enum_decl_node = tag_type->data.enumeration.decl_node;
32983298 AstNode *field_node = enum_decl_node->data.container_decl.fields.at(i);
32993299 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
50655065{
50665066 ZigType *enum_type = instruction->target->value->type;
50675067 assert(enum_type->id == ZigTypeIdEnum);
5068 if (enum_type->data.enumeration.non_exhaustive)
5069 zig_panic("TODO @tagName on non-exhaustive enum");
50685070
50695071 LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type);
50705072
src/ir.cpp+7-1
......@@ -22357,6 +22357,8 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
2235722357 if (instr_is_comptime(target)) {
2235822358 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))
2235922359 return ira->codegen->invalid_instruction;
22360 if (target->value->type->data.enumeration.non_exhaustive)
22361 zig_panic("TODO @tagName on non-exhaustive enum");
2236022362 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);
2236122363 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;
2236222364 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
......@@ -26471,7 +26473,11 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2647126473 bigint_incr(&field_index);
2647226474 }
2647326475 }
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 }
2647526481 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
2647626482 TypeEnumField *enum_field = &switch_type->data.enumeration.fields[i];
2647726483 if (buf_eql_str(enum_field->name, "_"))