Files
sx/examples/0760-modules-same-name-const-ambiguous.sx
agra 72f06a109b fix(lower): source-aware value-const resolution (own-wins / ambiguous) — close F2 [stdlib E2 attempt-3]
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).
2026-06-08 00:32:07 +03:00

15 lines
602 B
Plaintext

// issue 0105 / F2 — same-name VALUE const, two-flat-visible → AMBIGUOUS. `main`
// flat-imports two modules that each author a same-name `K` and authors none
// itself. A bare `K` reference can't be disambiguated, so the compiler emits a
// LOUD diagnostic (consistent with the type ambiguity at 0755 and the function
// ambiguity at 0724) and poisons the result — never a silent first-/last-wins
// pick.
#import "modules/std.sx";
#import "0760-modules-same-name-const-ambiguous/a.sx";
#import "0760-modules-same-name-const-ambiguous/b.sx";
main :: () -> s32 {
print("K={}\n", K);
0
}