| ... | ... | @@ -2691,11 +2691,11 @@ fn zirEnumDecl( |
| 2691 | 2691 | // This string needs to outlive the ZIR code. |
| 2692 | 2692 | const field_name = try decl_arena_allocator.dupe(u8, field_name_zir); |
| 2693 | 2693 | |
| 2694 | | const gop = enum_obj.fields.getOrPutAssumeCapacity(field_name); |
| 2695 | | if (gop.found_existing) { |
| 2694 | const gop_field = enum_obj.fields.getOrPutAssumeCapacity(field_name); |
| 2695 | if (gop_field.found_existing) { |
| 2696 | 2696 | const tree = try sema.getAstTree(block); |
| 2697 | 2697 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i); |
| 2698 | | const other_tag_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, gop.index); |
| 2698 | const other_tag_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, gop_field.index); |
| 2699 | 2699 | const msg = msg: { |
| 2700 | 2700 | const msg = try sema.errMsg(block, field_src, "duplicate enum field '{s}'", .{field_name}); |
| 2701 | 2701 | errdefer msg.destroy(gpa); |
| ... | ... | @@ -2714,10 +2714,22 @@ fn zirEnumDecl( |
| 2714 | 2714 | const tag_val = (try sema.resolveInstConst(block, src, tag_val_ref, "enum tag value must be comptime known")).val; |
| 2715 | 2715 | last_tag_val = tag_val; |
| 2716 | 2716 | const copied_tag_val = try tag_val.copy(decl_arena_allocator); |
| 2717 | | enum_obj.values.putAssumeCapacityNoClobberContext(copied_tag_val, {}, .{ |
| 2717 | const gop_val = enum_obj.values.getOrPutAssumeCapacityContext(copied_tag_val, .{ |
| 2718 | 2718 | .ty = enum_obj.tag_ty, |
| 2719 | 2719 | .mod = mod, |
| 2720 | 2720 | }); |
| 2721 | if (gop_val.found_existing) { |
| 2722 | const tree = try sema.getAstTree(block); |
| 2723 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i); |
| 2724 | const other_field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, gop_val.index); |
| 2725 | const msg = msg: { |
| 2726 | const msg = try sema.errMsg(block, field_src, "enum tag value {} already taken", .{tag_val.fmtValue(enum_obj.tag_ty, sema.mod)}); |
| 2727 | errdefer msg.destroy(gpa); |
| 2728 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); |
| 2729 | break :msg msg; |
| 2730 | }; |
| 2731 | return sema.failWithOwnedErrorMsg(msg); |
| 2732 | } |
| 2721 | 2733 | } else if (any_values) { |
| 2722 | 2734 | const tag_val = if (last_tag_val) |val| |
| 2723 | 2735 | try sema.intAdd(block, src, val, Value.one, enum_obj.tag_ty) |
| ... | ... | @@ -2725,10 +2737,22 @@ fn zirEnumDecl( |
| 2725 | 2737 | Value.zero; |
| 2726 | 2738 | last_tag_val = tag_val; |
| 2727 | 2739 | const copied_tag_val = try tag_val.copy(decl_arena_allocator); |
| 2728 | | enum_obj.values.putAssumeCapacityNoClobberContext(copied_tag_val, {}, .{ |
| 2740 | const gop_val = enum_obj.values.getOrPutAssumeCapacityContext(copied_tag_val, .{ |
| 2729 | 2741 | .ty = enum_obj.tag_ty, |
| 2730 | 2742 | .mod = mod, |
| 2731 | 2743 | }); |
| 2744 | if (gop_val.found_existing) { |
| 2745 | const tree = try sema.getAstTree(block); |
| 2746 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i); |
| 2747 | const other_field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, gop_val.index); |
| 2748 | const msg = msg: { |
| 2749 | const msg = try sema.errMsg(block, field_src, "enum tag value {} already taken", .{tag_val.fmtValue(enum_obj.tag_ty, sema.mod)}); |
| 2750 | errdefer msg.destroy(gpa); |
| 2751 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); |
| 2752 | break :msg msg; |
| 2753 | }; |
| 2754 | return sema.failWithOwnedErrorMsg(msg); |
| 2755 | } |
| 2732 | 2756 | } else { |
| 2733 | 2757 | tag_val_buf = .{ |
| 2734 | 2758 | .base = .{ .tag = .int_u64 }, |