zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 196ddf010c97f2faf69513e61099a233d4270795 (tree)
parent 8fa44969095caa293cb76b9a0b5fc0c0c270dc3b
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 28 Dec 2023 17:42:23 -0700

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.

Diffstat:
Msrc/Module.zig | 2+-
Msrc/Package/Module.zig | 3+++
2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/Module.zig b/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); diff --git a/src/Package/Module.zig b/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());