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.
This commit is contained in:
Andrew Kelley 2023-12-28 17:42:23 -07:00
parent 8fa4496909
commit 196ddf010c
2 changed files with 4 additions and 1 deletions

View File

@ -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);

View File

@ -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());