zig

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

commit 347196f905c083047fdc0a3b72656f1867973a13 (tree)
parent 075c103332effdac80d2c00e59f06ee0fea95b49
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Tue, 12 Mar 2024 20:25:54 +0000

Zcu: perform orphan checks against uncoerced function

Diffstat:
Msrc/InternPool.zig | 2+-
Msrc/Module.zig | 9+++++++--
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/InternPool.zig b/src/InternPool.zig @@ -9223,7 +9223,7 @@ pub fn funcTypeParamsLen(ip: *const InternPool, i: Index) u32 { return ip.extra.items[start + std.meta.fieldIndex(Tag.TypeFunction, "params_len").?]; } -fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index { +pub fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index { const tags = ip.items.items(.tag); return switch (tags[@intFromEnum(i)]) { .func_coerced => { diff --git a/src/Module.zig b/src/Module.zig @@ -3113,13 +3113,18 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { } } -pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, func_index: InternPool.Index) SemaError!void { +pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.Index) SemaError!void { const tracy = trace(@src()); defer tracy.end(); const gpa = zcu.gpa; const ip = &zcu.intern_pool; - const func = zcu.funcInfo(func_index); + + // We only care about the uncoerced function. + // We need to do this for the "orphaned function" check below to be valid. + const func_index = ip.unwrapCoercedFunc(maybe_coerced_func_index); + + const func = zcu.funcInfo(maybe_coerced_func_index); const decl_index = func.owner_decl; const decl = zcu.declPtr(decl_index);