aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-08-13 20:20:38 +0100
committerJacob Young <jacobly0@users.noreply.github.com>2024-08-17 18:50:10 -0400
commit50960fac80b1d04f7858215d963fa64a7583210b (patch)
tree5d407fb1c0bd21ddfcaddadcb835084674b0376e /src/Compilation.zig
parent4e5834a9f247c60fcc1d1da5f3b2c00efdb8f4e4 (diff)
downloadzig-50960fac80b1d04f7858215d963fa64a7583210b.tar.gz
zig-50960fac80b1d04f7858215d963fa64a7583210b.zip
compiler: be more cautious about source locations
Two fixes here. * Prevent a crash when sorting the list of analysis errors when some errors refer to lost source locations. These errors can be sorted anywhere in the list, because they are (in theory) guaranteed to never be emitted by the `resolveReferences` logic. This case occurs, for instance, when a declaration has compile errors in the initial update and is deleted in the second update. * Prevent a crash when resolving the source location for `entire_file` errors for a non-existent file. This is the bug underlying #20954. Resolves: #20954.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 5c49e96db2..8787d679e6 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -3203,8 +3203,14 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool {
if (ctx.err.*) |_| return lhs_index < rhs_index;
const errors = ctx.zcu.failed_analysis.values();
- const lhs_src_loc = errors[lhs_index].src_loc.upgrade(ctx.zcu);
- const rhs_src_loc = errors[rhs_index].src_loc.upgrade(ctx.zcu);
+ const lhs_src_loc = errors[lhs_index].src_loc.upgradeOrLost(ctx.zcu) orelse {
+ // LHS source location lost, so should never be referenced. Just sort it to the end.
+ return false;
+ };
+ const rhs_src_loc = errors[rhs_index].src_loc.upgradeOrLost(ctx.zcu) orelse {
+ // RHS source location lost, so should never be referenced. Just sort it to the end.
+ return true;
+ };
return if (lhs_src_loc.file_scope != rhs_src_loc.file_scope) std.mem.order(
u8,
lhs_src_loc.file_scope.sub_file_path,