Third of four fix-0102 sub-steps — the behaviour fix for NORMAL call sites.
Adds THE bare-name resolver `resolveBareCallee(name, caller_file)` over
fix-0102a's `module_fns` + `flat_import_graph` and routes the primary call
path through it:
- own-author wins: a file's bare call to a name IT authors binds its OWN
author, not the first-wins merge winner. (When the winner already is the
caller's own — every single-author and first-importer case — the resolver
returns `.none` so the existing path binds it byte-for-byte.)
- a bare call to a name two or more FLAT imports both provide is `.ambiguous`
and rejected with a loud diagnostic ("declared by multiple imported
modules — qualify the call"); a namespaced author never collides.
- a single flat-reachable author that differs from the winner binds that
author; otherwise `.none`.
The resolved shadow author lowers into its OWN FuncId via fix-0102b's
identity-addressable `lowerFunctionBodyInto` (shared `bareAuthorFuncId`
helper, also used by `lowerRetainedSameNameAuthors`). Only plain free
functions route — generic / comptime / foreign / builtin authors and any
scope-mangled / UFCS-aliased / locally-shadowed name fall straight to the
existing dispatch, so single-author / local / std / qualified resolution is
unchanged (full example suite stays green, including bundle.sx and the
comptime format/pack examples).
Examples 0722 (flat file per-source bind), 0723 (flat vs namespaced, no false
ambiguity), 0724 (ambiguous → diagnostic), 0725 (flat directory per-source
bind), 0727 (user namespace literally named __m0). Each fails on
wt-fix-0102-base (first-wins mis-bind / no diagnostic) and passes here. The
fix-0102b unit test now calls a per-module wrapper (main can't bare-call the
2-author name) and asserts the resolver's three variants directly.
Gate: zig build, zig build test (400/400), bash tests/run_examples.sh
(462 passed) all green.
19 lines
755 B
Plaintext
19 lines
755 B
Plaintext
// fix-0102c (issue 0102): two flat FILE imports each author a same-name free
|
|
// function `greet`. The first-wins import merge keeps exactly one `greet` in
|
|
// the merged scope, but each module's OWN code must bind its OWN author when it
|
|
// calls `greet` bare. `from_a` (in a.sx) returns 1; `from_b` (in b.sx) returns
|
|
// 2 — per-source binding, resolved by identity, not first-wins.
|
|
#import "modules/std.sx";
|
|
#import "0722-modules-flat-same-name-own/a.sx";
|
|
#import "0722-modules-flat-same-name-own/b.sx";
|
|
|
|
report :: (label: string, ok: bool) {
|
|
if ok { print("{}: ok\n", label); } else { print("{}: FAIL\n", label); }
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
report("from_a binds a.greet", from_a() == 1);
|
|
report("from_b binds b.greet", from_b() == 2);
|
|
0
|
|
}
|