commit 4a65cc4aca6fd03e80272a211e9b6c8c50716594 (tree)
parent fec502ec674e458a53e846abb875e6591c3eacfb
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date: Wed, 20 May 2026 09:51:36 +0100
Zcu: report outdated nav_ty when previous generation had a compile error
This logic existed when actually analyzing a `nav_ty` unit directly; it
was just missing in the code path which resolves a `nav_ty` unit due to
a `nav_val` being resolved.
Resolves: #35307
Diffstat:
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig
@@ -1872,15 +1872,22 @@ fn analyzeNavVal(
// that case and invalidate the dependee right now.
if (zcu.clearOutdatedState(.wrap(.{ .nav_ty = nav_id }))) {
assert(zir_decl.type_body == null); // otherwise we already resolved it with `Sema.ensureNavResolved`
- zcu.resetUnit(.wrap(.{ .nav_ty = nav_id }));
- try pt.addDependency(.wrap(.{ .nav_ty = nav_id }), .{ .nav_val = nav_id }); // inferred type depends on the value (that's us!)
+ const type_unit: AnalUnit = .wrap(.{ .nav_ty = nav_id });
+ const prev_type_failed = zcu.failed_analysis.contains(type_unit) or
+ zcu.transitive_failed_analysis.contains(type_unit);
+ zcu.resetUnit(type_unit);
+ try pt.addDependency(type_unit, .{ .nav_val = nav_id }); // inferred type depends on the value (that's us!)
if (comp.debugIncremental()) {
- const info = try zcu.incremental_debug_state.getUnitInfo(gpa, .wrap(.{ .nav_ty = nav_id }));
+ const info = try zcu.incremental_debug_state.getUnitInfo(gpa, type_unit);
info.last_update_gen = zcu.generation;
info.deps.clearRetainingCapacity();
}
- const type_changed: bool = if (old_nav.resolved) |r| r.type != nav_ty.toIntern() else true;
- if (type_changed) {
+ const type_outdated: bool = type_outdated: {
+ if (prev_type_failed) break :type_outdated true;
+ const r = old_nav.resolved orelse break :type_outdated true;
+ break :type_outdated r.type != nav_ty.toIntern();
+ };
+ if (type_outdated) {
try zcu.markDependeeOutdated(.marked_po, .{ .nav_ty = nav_id });
} else {
try zcu.markPoDependeeUpToDate(.{ .nav_ty = nav_id });
diff --git a/test/incremental/pointer_to_decl_with_astgen_error b/test/incremental/pointer_to_decl_with_astgen_error
@@ -0,0 +1,23 @@
+#update=initial version
+#file=main.zig
+const foo = {};
+pub fn main() void {
+ _ = &foo;
+}
+#expect_stdout=""
+
+#update=introduce use of undeclared identifier
+#file=main.zig
+const foo = something;
+pub fn main() void {
+ _ = &foo;
+}
+#expect_error=main.zig:1:13: error: use of undeclared identifier 'something'
+
+#update=revert use of undeclared identifier
+#file=main.zig
+const foo = {};
+pub fn main() void {
+ _ = &foo;
+}
+#expect_stdout=""