Commit 196ddf010c

Andrew Kelley <andrew@ziglang.org>
2023-12-29 01:42:23
frontend: fix populateTestFunctions accessing the wrong module
The test runner reads the list of test function pointers from its own builtin module, which is the root_mod, not main_mod.
1 parent 8fa4496
Changed files (2)
src/Package/Module.zig
@@ -466,6 +466,9 @@ pub fn createLimited(gpa: Allocator, options: LimitedOptions) Allocator.Error!*P
     return mod;
 }
 
+/// Asserts that the module has a builtin module, which is not true for non-zig
+/// modules such as ones only used for `@embedFile`, or the root module when
+/// there is no Zig Compilation Unit.
 pub fn getBuiltinDependency(m: Module) *Module {
     const result = m.deps.values()[0];
     assert(result.isBuiltin());
src/Module.zig
@@ -5307,7 +5307,7 @@ pub fn populateTestFunctions(
 ) !void {
     const gpa = mod.gpa;
     const ip = &mod.intern_pool;
-    const builtin_mod = mod.main_mod.getBuiltinDependency();
+    const builtin_mod = mod.root_mod.getBuiltinDependency();
     const builtin_file = (mod.importPkg(builtin_mod) catch unreachable).file;
     const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);
     const builtin_namespace = mod.namespacePtr(root_decl.src_namespace);