fix(stdlib/E4): own-wins at non-leaf bare-type sites + type-fn head ambiguity
attempt-6: address Adi's two in-scope findings (#3 deferred to E6). #1 E4-own-author-type-arg (silent-wrong): the bare-TYPE gate returned `.proceed` for the querying source's OWN author, so the non-leaf sites (reflection / type-arg / array-literal / type-value / match arm) dropped it and re-resolved a same-name flat import via global `findByName`. headTypeGate now resolves the own author to ITS per-source TypeId (mirroring selectNominalLeaf's own-wins, 0754); the type-as-value and type-match sites, which only consumed the poison bit and re-resolved globally, now route through the gate and use the `.resolved` author. size_of(Widget) with an own + imported Widget now yields main's own size, not the import's. #2 E4-type-fn-head-ambiguity (silent-wrong): headFnLeak only checked isNameVisible, so two flat same-name type-returning functions both reported "visible" and one was silently instantiated. It now diagnoses >=2 distinct direct flat type-fn authors (no own author) as ambiguous before the isNameVisible short-circuit, consistent with the parameterized struct / protocol heads and the leaf (0755/0767). Own / single / diamond-collapse type-fn heads still resolve. Regressions: 0768 (own-wins at every non-leaf bare-type site, fail-before reflection=16 -> pass-after 8) and 0769 (two flat Make type-fns -> ambiguity diagnostic exit 1). README: own-wins + type-fn-head ambiguity at every bare-type site.
This commit is contained in:
44
examples/0768-modules-own-wins-nonleaf-bare-type.sx
Normal file
44
examples/0768-modules-own-wins-nonleaf-bare-type.sx
Normal file
@@ -0,0 +1,44 @@
|
||||
// Own-wins (0754 / issue 0105 case 3) holds at EVERY non-leaf bare-type site,
|
||||
// not just the nominal leaf annotation. `main` flat-imports `dep.sx` (which
|
||||
// authors a same-name `Widget { a, b }` = 16 bytes and `Nums :: [2]s32` = 8
|
||||
// bytes) AND authors its OWN `Widget { a }` = 8 bytes and `Nums :: [2]s64` = 16
|
||||
// bytes. Each bare reference below must resolve to MAIN's own author — the gate's
|
||||
// source-keyed `.resolved` author — NOT whichever same-name flat import a global
|
||||
// `findByName` / `struct_template_map` pick would return:
|
||||
//
|
||||
// - reflection / type-arg slot `size_of(Widget)` → 8 (own)
|
||||
// - typed array-literal head `Nums.[…]` / size_of → 16 (own [2]s64)
|
||||
// - type-as-value `t : Type = Widget`
|
||||
// - type-category match arm `case Widget:` → own identity
|
||||
//
|
||||
// Regression (Phase E4 attempt-6, finding #1): before the bare-type gate carried
|
||||
// the OWN author's source-keyed TypeId into the non-leaf sites, an own author
|
||||
// produced `.proceed` and these sites fell through to a global `findByName` — so
|
||||
// `size_of(Widget)` printed the IMPORTED type's 16 and `case Widget:` matched the
|
||||
// imported nominal identity (describe → 222). `dep_sizes` proves dep's distinct
|
||||
// types still resolve to THEIR own 16 + 8 = 24 inside dep.
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "0768-modules-own-wins-nonleaf-bare-type/dep.sx";
|
||||
|
||||
Widget :: struct { a: s64; }
|
||||
Nums :: [2]s64;
|
||||
|
||||
describe :: ($T: Type) -> s32 {
|
||||
r := if T == {
|
||||
case Widget: 111;
|
||||
else: 222;
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
print("reflection={}\n", size_of(Widget));
|
||||
xs := Nums.[1, 2];
|
||||
print("array={}\n", size_of(Nums));
|
||||
t : Type = Widget;
|
||||
print("typeval_eq={}\n", t == Widget);
|
||||
print("match={}\n", describe(Widget));
|
||||
print("dep={}\n", dep_sizes());
|
||||
0
|
||||
}
|
||||
8
examples/0768-modules-own-wins-nonleaf-bare-type/dep.sx
Normal file
8
examples/0768-modules-own-wins-nonleaf-bare-type/dep.sx
Normal file
@@ -0,0 +1,8 @@
|
||||
// A flat-imported module authors its OWN `Widget { a, b }` (16 bytes) and
|
||||
// `Nums :: [2]s32` (8 bytes). The importing file (`main`) ALSO authors a
|
||||
// same-name `Widget { a }` (8 bytes) and `Nums :: [2]s64` (16 bytes) — its own
|
||||
// authors must win at EVERY bare-type site there (own-wins, 0754), while this
|
||||
// module's distinct types stay live via `dep_sizes`.
|
||||
Widget :: struct { a: s64; b: s64; }
|
||||
Nums :: [2]s32;
|
||||
dep_sizes :: () -> s64 { return size_of(Widget) + size_of(Nums); }
|
||||
21
examples/0769-modules-ambiguous-type-fn-head.sx
Normal file
21
examples/0769-modules-ambiguous-type-fn-head.sx
Normal file
@@ -0,0 +1,21 @@
|
||||
// A type-returning FUNCTION head (`Make(s64)` where `Make :: ($T) -> Type`) is
|
||||
// NON-transitive AND ambiguity-checked, exactly like the parameterized generic-
|
||||
// struct / protocol heads (0767) and the nominal leaf (0755). `main` flat-imports
|
||||
// two modules that each author a same-name `Make` type-fn with a different body
|
||||
// and authors none itself, so the bare `Make(s64)` head is a genuine collision —
|
||||
// it must emit the LOUD "type 'Make' is ambiguous" diagnostic and poison, NEVER
|
||||
// silently instantiate whichever single author `fn_ast_map` happens to hold.
|
||||
//
|
||||
// Regression (Phase E4 attempt-6, finding #2): before `headFnLeak` did bare-call
|
||||
// ambiguity selection it only checked `isNameVisible` (both authors ARE visible),
|
||||
// so two flat `Make` type-fns silently instantiated one author — `size_of(Make(s64))`
|
||||
// printed 16 (a.sx's two-field body) at exit 0 instead of the ambiguity diagnostic.
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "0769-modules-ambiguous-type-fn-head/a.sx";
|
||||
#import "0769-modules-ambiguous-type-fn-head/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("size={}\n", size_of(Make(s64)));
|
||||
0
|
||||
}
|
||||
7
examples/0769-modules-ambiguous-type-fn-head/a.sx
Normal file
7
examples/0769-modules-ambiguous-type-fn-head/a.sx
Normal file
@@ -0,0 +1,7 @@
|
||||
// One of two flat-imported authors of a same-name type-returning function
|
||||
// `Make :: ($T) -> Type`. Its body returns a two-field struct; b.sx's returns a
|
||||
// one-field struct, so a bare `Make(s64)` head is a genuine collision the
|
||||
// importing source cannot disambiguate.
|
||||
Make :: ($T: Type) -> Type {
|
||||
return struct { x: T; y: T; };
|
||||
}
|
||||
5
examples/0769-modules-ambiguous-type-fn-head/b.sx
Normal file
5
examples/0769-modules-ambiguous-type-fn-head/b.sx
Normal file
@@ -0,0 +1,5 @@
|
||||
// The second flat-imported author of same-name type-fn `Make`. Its distinct
|
||||
// one-field body makes a bare `Make(s64)` head ambiguous against a.sx's.
|
||||
Make :: ($T: Type) -> Type {
|
||||
return struct { x: T; };
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
reflection=8
|
||||
array=16
|
||||
typeval_eq=true
|
||||
match=111
|
||||
dep=24
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: type 'Make' is ambiguous: it is declared in multiple flat-imported modules; qualify the reference or remove the duplicate import
|
||||
--> examples/0769-modules-ambiguous-type-fn-head.sx:19:32
|
||||
|
|
||||
19 | print("size={}\n", size_of(Make(s64)));
|
||||
| ^^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user