From edf14777bae56c3a6a155c59f793dc432656c1de Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 18 Jun 2024 04:30:06 +0100 Subject: [PATCH] link.Wasm: correctly fetch source location when decl is a type The comment explains the situation here. This is a bit of a hack, and should be reworked when `Decl` is properly split up. --- src/link/Wasm/ZigObject.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/link/Wasm/ZigObject.zig b/src/link/Wasm/ZigObject.zig index 7d9e7e1310..cced85f800 100644 --- a/src/link/Wasm/ZigObject.zig +++ b/src/link/Wasm/ZigObject.zig @@ -484,7 +484,17 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d }); defer gpa.free(name); - switch (try zig_object.lowerConst(wasm_file, name, val, decl.navSrcLoc(mod).upgrade(mod))) { + // We want to lower the source location of `decl`. However, when generating + // lazy functions (for e.g. `@tagName`), `decl` may correspond to a type + // rather than a `Nav`! + // The future split of `Decl` into `Nav` and `Cau` may require rethinking this + // logic. For now, just get the source location conditionally as needed. + const decl_src = if (decl.typeOf(mod).toIntern() == .type_type) + decl.val.toType().srcLoc(mod) + else + decl.navSrcLoc(mod); + + switch (try zig_object.lowerConst(wasm_file, name, val, decl_src.upgrade(mod))) { .ok => |atom_index| { try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index); return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);