| ... | ... | @@ -4739,21 +4739,32 @@ pub fn addDependencyLoopErrors(zcu: *Zcu, eb: *std.zig.ErrorBundle.Wip) Allocato |
| 4739 | 4739 | const frame_limit = zcu.comp.reference_trace orelse 0; |
| 4740 | 4740 | try zcu.populateReferenceTrace(units.items[start_index], frame_limit, eb, &ref_trace); |
| 4741 | 4741 | |
| 4742 | if (units.items.len == 1) { |
| 4743 | // Don't do a complicated message with multiple notes, just do a single error message. |
| 4744 | assert(start_index == 0); |
| 4745 | const root_msg = addDependencyLoopErrorLine(zcu, eb, units.items[start_index], ref_trace.items) catch |err| switch (err) { |
| 4746 | error.AlreadyReported => return, // give up on the dep loop error |
| 4747 | error.OutOfMemory => |e| return e, |
| 4748 | }; |
| 4749 | try eb.root_list.append(eb.gpa, root_msg); |
| 4750 | continue; |
| 4751 | } |
| 4752 | |
| 4742 | 4753 | // Collect all notes first so we don't leave an incomplete root error message on `error.AlreadyReported`. |
| 4743 | 4754 | const note_buf = try gpa.alloc(std.zig.ErrorBundle.MessageIndex, units.items.len + 1); |
| 4744 | 4755 | defer gpa.free(note_buf); |
| 4745 | | note_buf[0] = addDependencyLoopNote(zcu, eb, units.items[start_index], ref_trace.items) catch |err| switch (err) { |
| 4756 | note_buf[0] = addDependencyLoopErrorLine(zcu, eb, units.items[start_index], ref_trace.items) catch |err| switch (err) { |
| 4746 | 4757 | error.AlreadyReported => return, // give up on the dep loop error |
| 4747 | 4758 | error.OutOfMemory => |e| return e, |
| 4748 | 4759 | }; |
| 4749 | 4760 | for (units.items[start_index + 1 ..], note_buf[1 .. units.items.len - start_index]) |unit, *note| { |
| 4750 | | note.* = addDependencyLoopNote(zcu, eb, unit, &.{}) catch |err| switch (err) { |
| 4761 | note.* = addDependencyLoopErrorLine(zcu, eb, unit, &.{}) catch |err| switch (err) { |
| 4751 | 4762 | error.AlreadyReported => return, // give up on the dep loop error |
| 4752 | 4763 | error.OutOfMemory => |e| return e, |
| 4753 | 4764 | }; |
| 4754 | 4765 | } |
| 4755 | 4766 | for (units.items[0..start_index], note_buf[units.items.len - start_index .. units.items.len]) |unit, *note| { |
| 4756 | | note.* = addDependencyLoopNote(zcu, eb, unit, &.{}) catch |err| switch (err) { |
| 4767 | note.* = addDependencyLoopErrorLine(zcu, eb, unit, &.{}) catch |err| switch (err) { |
| 4757 | 4768 | error.AlreadyReported => return, // give up on the dep loop error |
| 4758 | 4769 | error.OutOfMemory => |e| return e, |
| 4759 | 4770 | }; |
| ... | ... | @@ -4773,7 +4784,7 @@ pub fn addDependencyLoopErrors(zcu: *Zcu, eb: *std.zig.ErrorBundle.Wip) Allocato |
| 4773 | 4784 | @memcpy(notes, note_buf); |
| 4774 | 4785 | } |
| 4775 | 4786 | } |
| 4776 | | fn addDependencyLoopNote( |
| 4787 | fn addDependencyLoopErrorLine( |
| 4777 | 4788 | zcu: *Zcu, |
| 4778 | 4789 | eb: *std.zig.ErrorBundle.Wip, |
| 4779 | 4790 | source_unit: AnalUnit, |
| ... | ... | @@ -4789,7 +4800,16 @@ fn addDependencyLoopNote( |
| 4789 | 4800 | |
| 4790 | 4801 | const dep_node = zcu.dependency_loop_nodes.get(source_unit).?; |
| 4791 | 4802 | |
| 4792 | | const msg: std.zig.ErrorBundle.String = switch (dep_node.unit.unwrap()) { |
| 4803 | const msg: std.zig.ErrorBundle.String = if (dep_node.unit == source_unit) switch (source_unit.unwrap()) { |
| 4804 | .@"comptime" => unreachable, // cannot be involved in a dependency loop |
| 4805 | .nav_ty, .nav_val => try eb.printString("{f} depends on itself here", .{fmt_source}), |
| 4806 | .memoized_state => unreachable, // memoized_state definitely does not *directly* depend on itself |
| 4807 | .func => try eb.printString("{f} uses its own inferred error set here", .{fmt_source}), |
| 4808 | .type_layout => try eb.printString("{f} depends on itself {s}", .{ |
| 4809 | fmt_source, |
| 4810 | dep_node.reason.type_layout_reason.msg(), |
| 4811 | }), |
| 4812 | } else switch (dep_node.unit.unwrap()) { |
| 4793 | 4813 | .@"comptime" => unreachable, // cannot be involved in a dependency loop |
| 4794 | 4814 | .nav_val => |nav| try eb.printString("{f} uses value of declaration '{f}' here", .{ |
| 4795 | 4815 | fmt_source, ip.getNav(nav).fqn.fmt(ip), |