fix(stdlib/E5): source-aware value-const TYPE inference (F4)
Value-const SELECTION was source-aware for emission/folding (F2/R1/F1), but expression TYPE inference still read the global last-wins `module_const_map`, so an inferred return type / coercion on a same-name const borrowed another module's const TYPE (mixed-type same-name consts were never exercised by the attempt-1 same-typed goldens). - expr_typer.zig: the `.identifier` const path now selects via the source-aware `selectModuleConst` (own-wins / one-flat-visible) instead of the global `module_const_map`. The global map still gates "is this a const name?"; an unpartitioned registration-only author emits its global type, and an ambiguous bare reference yields `.unresolved` (the emission path diagnoses loudly). - lower.zig: expose `selectModuleConst` so the type-inference path shares the one author selector emission/folding already use. Audited every `module_const_map` read: emission (4102) and global-init copy (1447) were already source-aware (attempt-1); the binds-a-value predicate (6400) is a boolean, not a type read; the in-`selectModuleConst` read (13842) is the unwired fallback. No sibling inference site leaks. examples: 0793 mixed-type own-wins inference (A's `K:s32` yields `1`, not the global `f64`'s `1.000000`); 0794 mixed-type bare → loud ambiguous (exit 1), the inference change does not mask the ambiguity. Prior E5 surfaces (0786-0792), the 0105 set (0752-0758), E1-E4 type surfaces (0763-0785) and FFI byte-identical; 533 markers green.
This commit is contained in:
16
examples/0793-modules-same-name-const-type-infer.sx
Normal file
16
examples/0793-modules-same-name-const-type-infer.sx
Normal file
@@ -0,0 +1,16 @@
|
||||
// issue 0105 / F4 — same-name VALUE const TYPE inference is source-aware. Two
|
||||
// flat-imported modules each declare a top-level `K` with a DIFFERENT declared
|
||||
// TYPE (A: `s32`, B: `f64`) and an inferred-return function that reads `K` bare.
|
||||
// The inferred return type must come from each module's OWN `K` (own-wins), not
|
||||
// the global last-wins const TYPE: `a_k` infers A's `s32` and yields the integer
|
||||
// `1` (printed `1`, not `1.000000`), while `b_k` infers B's `f64` and yields
|
||||
// `2.500000`. Selection routes through the source-aware `selectModuleConst`, the
|
||||
// same author selector emission/folding use — type inference must agree.
|
||||
#import "modules/std.sx";
|
||||
#import "0793-modules-same-name-const-type-infer/a.sx";
|
||||
#import "0793-modules-same-name-const-type-infer/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("a={} b={}\n", a_k(), b_k());
|
||||
0
|
||||
}
|
||||
5
examples/0793-modules-same-name-const-type-infer/a.sx
Normal file
5
examples/0793-modules-same-name-const-type-infer/a.sx
Normal file
@@ -0,0 +1,5 @@
|
||||
// Module A authors its OWN `K` declared `s32`. Its inferred-return `a_k` reads
|
||||
// `K` bare; the inferred return type must be A's `s32`, so the value prints as
|
||||
// the integer `1`, never coerced to B's `f64`.
|
||||
K : s32 : 1;
|
||||
a_k :: () { return K; }
|
||||
5
examples/0793-modules-same-name-const-type-infer/b.sx
Normal file
5
examples/0793-modules-same-name-const-type-infer/b.sx
Normal file
@@ -0,0 +1,5 @@
|
||||
// Module B authors a DIFFERENT same-name `K` declared `f64` (a shadow of A's
|
||||
// `K`). Its inferred-return `b_k` reads `K` bare; the inferred return type must
|
||||
// be B's `f64`, so the value prints as `2.500000`.
|
||||
K : f64 : 2.5;
|
||||
b_k :: () { return K; }
|
||||
15
examples/0794-modules-same-name-const-type-ambiguous.sx
Normal file
15
examples/0794-modules-same-name-const-type-ambiguous.sx
Normal file
@@ -0,0 +1,15 @@
|
||||
// issue 0105 / F4 — same-name VALUE const with DIFFERENT declared TYPES across
|
||||
// two flat-imported modules (A: `s32`, B: `f64`), referenced bare at a mixed-type
|
||||
// site. A bare `K` here is genuinely ambiguous — there are ≥2 flat-visible same-
|
||||
// name authors — so it must diagnose loudly (exit 1), exactly as the same-typed
|
||||
// 0787 does. The type-inference change must NOT mask the ambiguity (inferring
|
||||
// `.unresolved` for the ambiguous reference) — the emission path still fires the
|
||||
// loud author-count diagnostic regardless of the consts' declared types.
|
||||
#import "modules/std.sx";
|
||||
#import "0794-modules-same-name-const-type-ambiguous/a.sx";
|
||||
#import "0794-modules-same-name-const-type-ambiguous/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("K={}\n", K);
|
||||
0
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// Module A authors `K` declared `s32`.
|
||||
K : s32 : 1;
|
||||
@@ -0,0 +1,2 @@
|
||||
// Module B authors a DIFFERENT same-name `K` declared `f64`.
|
||||
K : f64 : 2.5;
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
a=1 b=2.500000
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: 'K' is ambiguous: it is declared in multiple flat-imported modules; qualify the reference or remove the duplicate import
|
||||
--> examples/0794-modules-same-name-const-type-ambiguous.sx:13:21
|
||||
|
|
||||
13 | print("K={}\n", K);
|
||||
| ^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user