fix(lower): route remaining bare-name sites through resolver + close 0102 [0102d]
Final 0102 sub-step. fix-0102c landed resolveBareCallee and routed the primary call path + parameter target typing through it, leaving four other bare-name consumer sites on the old first-wins path. Route the SAME resolver through all four, gated exactly as the call path (plain top-level identifier, no scope-mangle / UFCS alias / local shadow; act on .func / .ambiguous, fall through on .none so single-author / local / std / qualified / foreign-single resolution is byte-for-byte unchanged): 1. Default-argument expansion (expandCallDefaults): omitted trailing args fill from the RESOLVED author's defaults, not the winner's. 2. Function-value conversion (closure(fn) and the bare-fn-as-value func_ref / fn-ptr / closure-coercion path): captures the resolved author's FuncId. 3. Free-function UFCS (recv.fn() -> fn(recv, ...)): dispatches the resolved author for the receiver's source. 4. Comptime #run of a bare call: lowerMainAndComptime now sets current_source_file per decl, so a `NAME :: #run f()` in an imported module resolves f from THAT module's flat imports (own-author wins) instead of the main file's perspective (which made it spuriously ambiguous). Regression tests: examples/0730-0734 (default-arg, closure+fn-value, UFCS, comptime #run, UFCS-ambiguity), each fails on pre-fix code and passes after. issues/0102-flat-import-same-signature-collision.md written RESOLVED with the 4-sub-step root cause and regression-test paths.
This commit is contained in:
20
examples/0730-modules-flat-same-name-default-arg.sx
Normal file
20
examples/0730-modules-flat-same-name-default-arg.sx
Normal file
@@ -0,0 +1,20 @@
|
||||
// fix-0102d site 1 (issue 0102): two flat FILE imports each author a same-name
|
||||
// free function `cfg` with a DIFFERENT default value for its trailing param —
|
||||
// a.sx defaults to 10, b.sx to 20. Each module calls `cfg()` bare with the arg
|
||||
// OMITTED. The omitted trailing arg must be filled from the RESOLVED author's
|
||||
// default (own-author wins), not the first-wins winner's. Before the fix,
|
||||
// `from_b`'s `cfg()` expanded to the winner a.sx's default (10) and returned 10.
|
||||
// Regression: per-source default-argument expansion.
|
||||
#import "modules/std.sx";
|
||||
#import "0730-modules-flat-same-name-default-arg/a.sx";
|
||||
#import "0730-modules-flat-same-name-default-arg/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.cfg default (10)", from_a() == 10);
|
||||
report("from_b binds b.cfg default (20)", from_b() == 20);
|
||||
0
|
||||
}
|
||||
5
examples/0730-modules-flat-same-name-default-arg/a.sx
Normal file
5
examples/0730-modules-flat-same-name-default-arg/a.sx
Normal file
@@ -0,0 +1,5 @@
|
||||
// a.sx authors `cfg` defaulting to 10. Imported first, so it is the first-wins
|
||||
// merge winner. `from_a` calls `cfg()` with the arg omitted — own == winner →
|
||||
// existing default-expansion path, byte-for-byte unchanged.
|
||||
cfg :: (n: s64 = 10) -> s64 { return n; }
|
||||
from_a :: () -> s64 { return cfg(); }
|
||||
5
examples/0730-modules-flat-same-name-default-arg/b.sx
Normal file
5
examples/0730-modules-flat-same-name-default-arg/b.sx
Normal file
@@ -0,0 +1,5 @@
|
||||
// b.sx authors its OWN `cfg` defaulting to 20. `from_b`'s `cfg()` omits the
|
||||
// arg; the omitted trailing default must come from b.sx's author (20), not the
|
||||
// first-wins winner from a.sx (10).
|
||||
cfg :: (n: s64 = 20) -> s64 { return n; }
|
||||
from_b :: () -> s64 { return cfg(); }
|
||||
22
examples/0731-modules-flat-same-name-closure.sx
Normal file
22
examples/0731-modules-flat-same-name-closure.sx
Normal file
@@ -0,0 +1,22 @@
|
||||
// fix-0102d site 2 (issue 0102): two flat FILE imports each author a same-name
|
||||
// free function `pick` (a.sx returns 1, b.sx returns 2). Each module takes
|
||||
// `pick` as a function VALUE — both as `closure(pick)` and as a bare-name
|
||||
// fn-pointer binding (`g : () -> s64 = pick`). The captured FuncId must be the
|
||||
// RESOLVED author's (own-author wins), not the first-wins winner's. Before the
|
||||
// fix, b.sx's `closure(pick)` / `pick`-as-value both captured a.sx's winner
|
||||
// (1). Regression: per-source function-value conversion (closure + func_ref).
|
||||
#import "modules/std.sx";
|
||||
#import "0731-modules-flat-same-name-closure/a.sx";
|
||||
#import "0731-modules-flat-same-name-closure/b.sx";
|
||||
|
||||
report :: (label: string, ok: bool) {
|
||||
if ok { print("{}: ok\n", label); } else { print("{}: FAIL\n", label); }
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
report("from_a closure binds a.pick (1)", from_a_closure() == 1);
|
||||
report("from_b closure binds b.pick (2)", from_b_closure() == 2);
|
||||
report("from_a fn-value binds a.pick (1)", from_a_value() == 1);
|
||||
report("from_b fn-value binds b.pick (2)", from_b_value() == 2);
|
||||
0
|
||||
}
|
||||
6
examples/0731-modules-flat-same-name-closure/a.sx
Normal file
6
examples/0731-modules-flat-same-name-closure/a.sx
Normal file
@@ -0,0 +1,6 @@
|
||||
// a.sx authors `pick` returning 1. Imported first → first-wins winner.
|
||||
// `from_a_closure` / `from_a_value` take a.sx's own author (own == winner →
|
||||
// existing path, byte-for-byte unchanged).
|
||||
pick :: () -> s64 { return 1; }
|
||||
from_a_closure :: () -> s64 { f := closure(pick); return f(); }
|
||||
from_a_value :: () -> s64 { g : () -> s64 = pick; return g(); }
|
||||
6
examples/0731-modules-flat-same-name-closure/b.sx
Normal file
6
examples/0731-modules-flat-same-name-closure/b.sx
Normal file
@@ -0,0 +1,6 @@
|
||||
// b.sx authors its OWN `pick` returning 2. Taking `pick` as a value —
|
||||
// `closure(pick)` or `g : () -> s64 = pick` — must capture b.sx's author (2),
|
||||
// not the first-wins winner from a.sx (1).
|
||||
pick :: () -> s64 { return 2; }
|
||||
from_b_closure :: () -> s64 { f := closure(pick); return f(); }
|
||||
from_b_value :: () -> s64 { g : () -> s64 = pick; return g(); }
|
||||
19
examples/0732-modules-flat-same-name-ufcs.sx
Normal file
19
examples/0732-modules-flat-same-name-ufcs.sx
Normal file
@@ -0,0 +1,19 @@
|
||||
// fix-0102d site 3 (issue 0102): two flat FILE imports each author a same-name
|
||||
// free function `bump` (a.sx adds 1, b.sx adds 100). Each module dispatches it
|
||||
// via free-function UFCS — `v.bump()` lowers to `bump(v)`. The dispatched
|
||||
// author must be the RESOLVED one for the receiver's source (own-author wins),
|
||||
// not the first-wins winner. Before the fix, b.sx's `v.bump()` dispatched
|
||||
// a.sx's winner (+1 → 11). Regression: per-source free-function UFCS dispatch.
|
||||
#import "modules/std.sx";
|
||||
#import "0732-modules-flat-same-name-ufcs/a.sx";
|
||||
#import "0732-modules-flat-same-name-ufcs/b.sx";
|
||||
|
||||
report :: (label: string, ok: bool) {
|
||||
if ok { print("{}: ok\n", label); } else { print("{}: FAIL\n", label); }
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
report("from_a v.bump() binds a.bump (+1)", from_a_ufcs() == 11);
|
||||
report("from_b v.bump() binds b.bump (+100)", from_b_ufcs() == 110);
|
||||
0
|
||||
}
|
||||
5
examples/0732-modules-flat-same-name-ufcs/a.sx
Normal file
5
examples/0732-modules-flat-same-name-ufcs/a.sx
Normal file
@@ -0,0 +1,5 @@
|
||||
// a.sx authors `bump` adding 1. Imported first → first-wins winner. `from_a`'s
|
||||
// `v.bump()` resolves a.sx's own author (own == winner → existing UFCS path,
|
||||
// byte-for-byte unchanged).
|
||||
bump :: (x: s64) -> s64 { return x + 1; }
|
||||
from_a_ufcs :: () -> s64 { v : s64 = 10; return v.bump(); }
|
||||
4
examples/0732-modules-flat-same-name-ufcs/b.sx
Normal file
4
examples/0732-modules-flat-same-name-ufcs/b.sx
Normal file
@@ -0,0 +1,4 @@
|
||||
// b.sx authors its OWN `bump` adding 100. `from_b`'s `v.bump()` must dispatch
|
||||
// b.sx's author (+100 → 110), not the first-wins winner from a.sx (+1).
|
||||
bump :: (x: s64) -> s64 { return x + 100; }
|
||||
from_b_ufcs :: () -> s64 { v : s64 = 10; return v.bump(); }
|
||||
21
examples/0733-modules-flat-same-name-comptime-run.sx
Normal file
21
examples/0733-modules-flat-same-name-comptime-run.sx
Normal file
@@ -0,0 +1,21 @@
|
||||
// fix-0102d site 4 (issue 0102): two flat FILE imports each author a same-name
|
||||
// free function `compute` (a.sx returns 7, b.sx returns 70) and each evaluates
|
||||
// it at comptime via `NAME :: #run compute();`. The #run body must resolve the
|
||||
// bare callee from ITS OWN module's source context (own-author wins), so a.sx's
|
||||
// const is 7 and b.sx's is 70. Before the fix, the #run body lowered with the
|
||||
// main file's source perspective, where `compute` is authored by two flat
|
||||
// imports and neither is main's own — so it was reported AMBIGUOUS and the
|
||||
// build failed. Regression: per-source comptime #run callee resolution.
|
||||
#import "modules/std.sx";
|
||||
#import "0733-modules-flat-same-name-comptime-run/a.sx";
|
||||
#import "0733-modules-flat-same-name-comptime-run/b.sx";
|
||||
|
||||
report :: (label: string, ok: bool) {
|
||||
if ok { print("{}: ok\n", label); } else { print("{}: FAIL\n", label); }
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
report("a.sx #run binds a.compute (7)", get_a() == 7);
|
||||
report("b.sx #run binds b.compute (70)", get_b() == 70);
|
||||
0
|
||||
}
|
||||
6
examples/0733-modules-flat-same-name-comptime-run/a.sx
Normal file
6
examples/0733-modules-flat-same-name-comptime-run/a.sx
Normal file
@@ -0,0 +1,6 @@
|
||||
// a.sx authors `compute` returning 7 and evaluates it at comptime. Imported
|
||||
// first → first-wins winner; own == winner, but the #run must still lower in
|
||||
// a.sx's source context so the bare `compute` resolves at all (not ambiguous).
|
||||
compute :: () -> s64 { return 7; }
|
||||
A_VAL :: #run compute();
|
||||
get_a :: () -> s64 { return A_VAL; }
|
||||
6
examples/0733-modules-flat-same-name-comptime-run/b.sx
Normal file
6
examples/0733-modules-flat-same-name-comptime-run/b.sx
Normal file
@@ -0,0 +1,6 @@
|
||||
// b.sx authors its OWN `compute` returning 70. Its `#run compute()` must bind
|
||||
// b.sx's author (70) — own-author wins in b.sx's source context — not the
|
||||
// first-wins winner from a.sx (7).
|
||||
compute :: () -> s64 { return 70; }
|
||||
B_VAL :: #run compute();
|
||||
get_b :: () -> s64 { return B_VAL; }
|
||||
16
examples/0734-modules-flat-same-name-ufcs-ambiguous.sx
Normal file
16
examples/0734-modules-flat-same-name-ufcs-ambiguous.sx
Normal file
@@ -0,0 +1,16 @@
|
||||
// fix-0102d site 3 ambiguity (issue 0102): two flat FILE imports each author a
|
||||
// same-name free function `dup`, and the MAIN file (which authors neither)
|
||||
// dispatches it via free-function UFCS `v.dup()`. With two distinct flat
|
||||
// authors reachable and no own-author to prefer, the call is ambiguous — the
|
||||
// UFCS dispatch site must emit the loud "qualify the call" diagnostic rather
|
||||
// than silently binding the first-wins winner. Mirrors 0724 (the bare-call
|
||||
// ambiguity) one site over.
|
||||
#import "modules/std.sx";
|
||||
#import "0734-modules-flat-same-name-ufcs-ambiguous/a.sx";
|
||||
#import "0734-modules-flat-same-name-ufcs-ambiguous/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
v : s64 = 10;
|
||||
print("{}\n", v.dup());
|
||||
0
|
||||
}
|
||||
2
examples/0734-modules-flat-same-name-ufcs-ambiguous/a.sx
Normal file
2
examples/0734-modules-flat-same-name-ufcs-ambiguous/a.sx
Normal file
@@ -0,0 +1,2 @@
|
||||
// a.sx authors `dup` (+1). One of two distinct flat authors of `dup`.
|
||||
dup :: (x: s64) -> s64 { return x + 1; }
|
||||
3
examples/0734-modules-flat-same-name-ufcs-ambiguous/b.sx
Normal file
3
examples/0734-modules-flat-same-name-ufcs-ambiguous/b.sx
Normal file
@@ -0,0 +1,3 @@
|
||||
// b.sx authors its OWN `dup` (+2) — the second distinct flat author. Main
|
||||
// imports both and authors neither, so `v.dup()` from main is ambiguous.
|
||||
dup :: (x: s64) -> s64 { return x + 2; }
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
from_a binds a.cfg default (10): ok
|
||||
from_b binds b.cfg default (20): ok
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
from_a closure binds a.pick (1): ok
|
||||
from_b closure binds b.pick (2): ok
|
||||
from_a fn-value binds a.pick (1): ok
|
||||
from_b fn-value binds b.pick (2): ok
|
||||
1
examples/expected/0732-modules-flat-same-name-ufcs.exit
Normal file
1
examples/expected/0732-modules-flat-same-name-ufcs.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
from_a v.bump() binds a.bump (+1): ok
|
||||
from_b v.bump() binds b.bump (+100): ok
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
a.sx #run binds a.compute (7): ok
|
||||
b.sx #run binds b.compute (70): ok
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: 'dup' is ambiguous; declared by multiple imported modules — qualify the call
|
||||
--> examples/0734-modules-flat-same-name-ufcs-ambiguous.sx:14:19
|
||||
|
|
||||
14 | print("{}\n", v.dup());
|
||||
| ^^^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user