E2 retained per-source const declarations but left the const READ path on the
global last-wins `module_const_map`, so a module's OWN reference to a same-name
const bound the LAST global author (F2: a.sx `K::1`, b.sx `K::2`, main flat-imports
both → both read B's K). Complete the const analog of the type (`selectNominalLeaf`)
and callable (`selectPlainCallableAuthor`) source-aware models.
- `selectModuleConst`: own-wins; exactly one flat-visible author → it; ≥2 distinct
flat-visible → `.ambiguous` (loud diagnostic, consistent with 0755/0724); none
→ `.none`. Reads the SELECTED author's per-source value (`module_consts_by_source`)
and folds its RHS over the global leaf map, so a const-EXPRESSION chain
(`N :: M + 1`, M flat-imported) still resolves M.
- Rewire `comptimeIntNamed` / `lookupFloatName` / `nameIsFloatTyped`, the runtime
identifier path, and the global-init-from-const path through it; drop the now
subsumed `moduleConstBareInvisible` gate.
- program_index: `moduleConst{Int,Float,IsFloatTyped}With` fold a selected `ci`.
Examples: 0759 (own-wins value const, a=1 b=2) + 0760 (two-flat-visible →
ambiguous). Single-author byte-identical (run_examples 498/0, 496 prior unchanged;
zig build test 423/423; corpus sweep 515 no-crash; m3te ios-sim exit 0).
17 lines
783 B
Plaintext
17 lines
783 B
Plaintext
// issue 0105 / F2 — same-name VALUE const, own-wins. Two flat-imported modules
|
|
// each declare a top-level `K` with a different value and a function that reads
|
|
// `K` bare. Each function's OWN reference must bind ITS OWN module's `K`
|
|
// (own-wins), exactly as same-name structs (0754) and functions (0722) do —
|
|
// NOT the global last-wins author. Pre-fix both `a_k` and `b_k` returned B's
|
|
// `K` (the const READ path read the global last-wins `module_const_map`); now
|
|
// `a_k` returns 1 and `b_k` returns 2, resolved by the source-aware const
|
|
// author selector (`selectModuleConst`).
|
|
#import "modules/std.sx";
|
|
#import "0759-modules-same-name-const-own/a.sx";
|
|
#import "0759-modules-same-name-const-own/b.sx";
|
|
|
|
main :: () -> s32 {
|
|
print("a={} b={}\n", a_k(), b_k());
|
|
0
|
|
}
|