From 9f086f84f53de4eb23d96fe611c071f27405a660 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 6 Dec 2024 06:22:32 +0000 Subject: [PATCH] Zcu: allow test declarations to be failed The introduction of the `extended(astgen_error())` instruction allows a `test` declaration to be unresolved, i.e. the declaration doesn't even contain a `func`. I could modify AstGen to not do this, but it makes more sense to just handle this case when collecting test functions. Note that tests under incremental compilation are currently broken if you ever remove all references to a test; this is tracked as a subtask of #21165. --- src/Zcu/PerThread.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index 18494a68366e..aeda9ea1b15e 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -2511,6 +2511,19 @@ pub fn populateTestFunctions( for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_nav_index| { const test_nav = ip.getNav(test_nav_index); + + { + // The test declaration might have failed; if that's the case, just return, as we'll + // be emitting a compile error anyway. + const cau = test_nav.analysis_owner.unwrap().?; + const anal_unit: AnalUnit = .wrap(.{ .cau = cau }); + if (zcu.failed_analysis.contains(anal_unit) or + zcu.transitive_failed_analysis.contains(anal_unit)) + { + return; + } + } + const test_nav_name = test_nav.fqn; const test_nav_name_len = test_nav_name.length(ip); const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.Uav = n: {