Files
sx/examples/0741-modules-flat-same-name-bare-pack-winner.sx
agra 82fc71ccbe fix(lower): route early pack/comptime dispatch through SelectedFunc [stdlib C attempt-3]
lowerCall's early pack/comptime/generic dispatch keyed off the first-wins
winner (`fn_ast_map.get(early_name)`) BEFORE the main dispatch consumes the
selected same-name author. Under a genuine flat same-name collision where the
caller's own author is a plain free fn but the first-wins winner is a comptime
pack `(..$args)` (or comptime-param / generic), the early path invoked the
WINNER — so `CallResolver.plan` (which selects the own plain author) and
lowering disagreed about which function a bare call names.

Confirms reviewer finding C-review-1. The earlier manager ground-truth got
`show_b=2` because it used a slice variadic `(..xs: []s64)` — NOT a pack fn
(`isPackParam` false), so it never hit the early dispatch. The reviewer used a
comptime pack `(..$args)` (`isPackFn` true), which does. Both observations are
correct for their respective shapes; the bug is real for the comptime-pack
winner.

Fix: the early dispatch reads the SAME author the selector chose
(`sel_author.decl`) when a collision rerouted the call, else the winner
(common path, byte-identical). The selector only ever returns a plain free fn
(`isPlainFreeFn` excludes type-params / comptime / pack), so a selected author
falls through to the main dispatch that binds it via `SelectedFunc`.

Regression: examples/0741-modules-flat-same-name-bare-pack-winner — a.sx
(imported first) authors `f` as a comptime pack (first-wins winner); b.sx
authors its own plain `f`; b's bare `f()` must return 2 (own author), not 1
(the pack). Fails on 2dd6c3c (b: f() = 1), passes after.

Gate: zig build + zig build test (412/412) + run_examples (477/0) +
m3te ios-sim exit 0.
2026-06-07 12:40:00 +03:00

19 lines
1.0 KiB
Plaintext

// Regression (issue 0102, Phase C): a BARE call whose own author is a plain free
// fn must DISPATCH to that author, not the first-wins winner — even when the
// winner is a comptime PACK (`..$args`) of the same name. a.sx (imported first)
// authors `f` as a pack → first-wins winner; b.sx authors its OWN plain `f`. In
// b.sx, `f()` must reach b.f (returns 2). Before the fix, lowerCall's early
// pack/comptime/generic dispatch keyed off the first-wins winner (a's pack) and
// invoked it (returns 1) BEFORE consuming the selected author — so plan-selected
// author and lowered+dispatched author disagreed. The early dispatch now reads
// the SAME `SelectedFunc` the main dispatch binds (fix-0102 F2).
#import "modules/std.sx";
#import "0741-modules-flat-same-name-bare-pack-winner/a.sx";
#import "0741-modules-flat-same-name-bare-pack-winner/b.sx";
main :: () -> s32 {
show_a(); // a-side: own == winner (the pack) → returns 1, byte-for-byte unchanged
show_b(); // b-side: selected own plain author → returns 2, not the pack winner
0
}