| ... | ... | @@ -2631,9 +2631,24 @@ fn validateUnionInit( |
| 2631 | 2631 | union_ptr: Air.Inst.Ref, |
| 2632 | 2632 | ) CompileError!void { |
| 2633 | 2633 | if (instrs.len != 1) { |
| 2634 | | // TODO add note for other field |
| 2635 | | // TODO add note for union declared here |
| 2636 | | return sema.fail(block, init_src, "only one union field can be active at once", .{}); |
| 2634 | const msg = msg: { |
| 2635 | const msg = try sema.errMsg( |
| 2636 | block, |
| 2637 | init_src, |
| 2638 | "cannot initialize multiple union fields at once, unions can only have one active field", |
| 2639 | .{}, |
| 2640 | ); |
| 2641 | errdefer msg.destroy(sema.gpa); |
| 2642 | |
| 2643 | for (instrs[1..]) |inst| { |
| 2644 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 2645 | const inst_src: LazySrcLoc = .{ .node_offset_back2tok = inst_data.src_node }; |
| 2646 | try sema.errNote(block, inst_src, msg, "additional initializer here", .{}); |
| 2647 | } |
| 2648 | try sema.mod.errNoteNonLazy(union_obj.srcLoc(), msg, "union declared here", .{}); |
| 2649 | break :msg msg; |
| 2650 | }; |
| 2651 | return sema.failWithOwnedErrorMsg(msg); |
| 2637 | 2652 | } |
| 2638 | 2653 | |
| 2639 | 2654 | const field_ptr = instrs[0]; |