fix(lower): fn-value site lazily lowers winner only on resolver .none [0102d F1]

The bare-fn-as-value site (func_ref / fn-ptr / closure coercion) eagerly
lazily-lowered the name-keyed first-wins WINNER before the resolveBareCallee
block could reroute a genuine flat same-name collision to its per-source
author. Taking a SHADOW author's fn value therefore lowered (and could
mis-diagnose) the unused winner's body. Move lazyLowerFunction INSIDE blk_fv
onto the `.none` fallback only, mirroring the closure(fn) and free-function
UFCS sites: on `.func` use the resolved author's FuncId and never touch the
winner; on `.none` fall through to lazy-lower + resolveFuncByName the winner.

Regression: examples/0735-modules-flat-same-name-fn-value-winner — the
first-wins winner's body is independently broken and never used; a shadow
taken as a function value binds the shadow and runs (exit 0) while the winner
is not lowered. Fails-before (unresolved symbol in the winner), passes-after.
This commit is contained in:
agra
2026-06-06 16:41:01 +03:00
parent bd24996d8b
commit 96e3d2d5ae
8 changed files with 46 additions and 6 deletions

View File

@@ -3250,14 +3250,13 @@ pub const Lowering = struct {
const str = self.builder.constString(sid);
break :blk self.builder.boxAny(str, .string);
}
if (!self.lowered_functions.contains(eff_fn_name)) {
self.lazyLowerFunction(eff_fn_name);
}
// fix-0102d site 2: taking a bare same-name fn as a VALUE
// (func_ref, fn-ptr / closure coercion) must capture the
// RESOLVED author's FuncId for a genuine flat collision, not
// the first-wins winner's. Plain bare name only; `.ambiguous`
// → loud diagnostic; `.none` → existing first-wins path.
// → loud diagnostic; `.none` → existing first-wins path. The
// winner is lazily lowered ONLY on `.none` — a rerouted value
// never uses the winner, so its body must not be lowered.
const value_fid: ?FuncId = blk_fv: {
if (std.mem.eql(u8, eff_fn_name, id.name) and
self.program_index.ufcs_alias_map.get(id.name) == null and
@@ -3275,6 +3274,9 @@ pub const Lowering = struct {
}
}
}
if (!self.lowered_functions.contains(eff_fn_name)) {
self.lazyLowerFunction(eff_fn_name);
}
break :blk_fv self.resolveFuncByName(eff_fn_name);
};
if (value_fid) |fid| {