fix(stdlib/E4): carry full author outcome through the bare-TYPE gate (ambiguity at every site)

attempt-4 gated every bare-type-reference site for VISIBILITY via a boolean
leak-check that only caught not-visible and DROPPED the ambiguous outcome, so two
DIRECT flat same-name type authors (the 0755/0105 ambiguity case) fell through to
a global findByName / struct_template_map pick at the non-leaf sites.

Unified author-outcome fix (one path, every site consumes it):

- flatTypeAuthorCount: ≥2 distinct flat authors that do NOT all collapse onto one
  shared TypeId are now `.ambiguous` even when none carries a concrete TypeId yet —
  two same-name GENERIC TEMPLATES (template name registered in no findByName slot)
  are a genuine collision, exactly like two registered structs. Identical-target
  authors (diamond import / two aliases onto the same target) still collapse to
  `.one`, so all valid cases stay byte-identical.

- headTypeGate: the complete source-aware author outcome (.proceed / .resolved /
  .ambiguous / .not_visible) for an unqualified bare TYPE head, emitting the loud
  ambiguity diagnostic (consistent with the leaf / 0755) or the not-visible
  diagnostic. headTypeLeak is now its poison-vs-proceed projection, so every head /
  instantiation / alias-decl / match site poisons on ambiguity with the right
  message. Reflection / type-arg and array/vector-literal identifier heads consume
  `.resolved` to use the source-keyed TypeId, never a global findByName pick.

Regression examples/0767: size_of(Thing) / Nums.[1,2] / Box(s64) / t:Type=Thing /
case Thing: with two direct flat same-name authors each emit the ambiguity
diagnostic, exit 1 (fail-before on bb8f7dc: exit 0 / cascade). 0763/0764/0765/0766
/0755/0706/0544/0105 + FFI byte-identical. README: bare-type ambiguity is enforced
at every reference site.
This commit is contained in:
agra
2026-06-08 14:15:34 +03:00
parent bb8f7dc5ec
commit 382f78f49b
8 changed files with 209 additions and 48 deletions

View File

@@ -0,0 +1,39 @@
// Bare-TYPE references are NON-transitive AND ambiguity-checked at every site,
// not just the nominal leaf annotation (0755). `main` flat-imports two modules
// that each author a same-name `Thing` / `Box` / `Nums` and authors none itself,
// so EACH of the following bare forms is a genuine collision the source cannot
// disambiguate — and each must emit the LOUD "type ... is ambiguous" diagnostic
// (consistent with the leaf, 0755) and poison the result, NEVER silently pick a
// global `findByName` / `struct_template_map` author:
//
// - reflection / type-arg slot `size_of(Thing)`
// - typed array/vector-literal `Nums.[1, 2]`
// - parameterized generic head `Box(s64)`
// - type-as-value `t : Type = Thing`
// - type-category match arm `case Thing:`
//
// Regression (Phase E4 attempt-5): before the bare-type gate carried the full
// source-aware author outcome, these non-leaf sites used a boolean leak-check
// that dropped the AMBIGUOUS outcome — two direct flat same-name authors fell
// through to a global pick (exit 0 / cascade) instead of the loud diagnostic.
#import "modules/std.sx";
#import "0767-modules-ambiguous-bare-type-forms/a.sx";
#import "0767-modules-ambiguous-bare-type-forms/b.sx";
describe :: ($T: Type) -> s32 {
r := if T == {
case Thing: 1;
else: 0;
}
r
}
main :: () -> s32 {
sz := size_of(Thing);
xs := Nums.[1, 2];
x : Box(s64) = .{ v = 3 };
t : Type = Thing;
d := describe(s64);
0
}

View File

@@ -0,0 +1,6 @@
// One of two flat-imported authors of same-name types `Thing` / `Box` / `Nums`.
// With both modules flat-visible from a file that authors none itself, every
// bare reference to these names is genuinely ambiguous.
Thing :: struct { a: s64; }
Box :: struct($T: Type) { v: T; }
Nums :: [2]s64;

View File

@@ -0,0 +1,7 @@
// The second flat-imported author of same-name `Thing` / `Box` / `Nums`. The
// distinct shapes (`Thing` a separate nominal identity, `Box` a separate generic
// template, `Nums` aliased to a different element width) make each bare
// reference a real collision the importing source cannot disambiguate.
Thing :: struct { a: s64; }
Box :: struct($T: Type) { v: T; }
Nums :: [2]s32;

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,29 @@
error: type 'Thing' is ambiguous: it is declared in multiple flat-imported modules; qualify the reference or remove the duplicate import
--> examples/0767-modules-ambiguous-bare-type-forms.sx:33:19
|
33 | sz := size_of(Thing);
| ^^^^^
error: type 'Nums' is ambiguous: it is declared in multiple flat-imported modules; qualify the reference or remove the duplicate import
--> examples/0767-modules-ambiguous-bare-type-forms.sx:34:11
|
34 | xs := Nums.[1, 2];
| ^^^^
error: type 'Box' is ambiguous: it is declared in multiple flat-imported modules; qualify the reference or remove the duplicate import
--> examples/0767-modules-ambiguous-bare-type-forms.sx:35:9
|
35 | x : Box(s64) = .{ v = 3 };
| ^^^^^^^^
error: type 'Thing' is ambiguous: it is declared in multiple flat-imported modules; qualify the reference or remove the duplicate import
--> examples/0767-modules-ambiguous-bare-type-forms.sx:36:16
|
36 | t : Type = Thing;
| ^^^^^
error: type 'Thing' is ambiguous: it is declared in multiple flat-imported modules; qualify the reference or remove the duplicate import
--> examples/0767-modules-ambiguous-bare-type-forms.sx:26:14
|
26 | case Thing: 1;
| ^^^^^