fix(diag): source-key local_type_names so a caller block-local can't leak into an imported template field [stdlib E3 attempt-5]
A block-local type is visible only within the source that declares it. The
global `local_type_names` set was source-insensitive, so an imported generic
template's field (resolved in the template's source context, attempt-4) could
bind a type the CALLER declared block-local — silently compiling an undeclared
imported field instead of diagnosing it.
Key `local_type_names` by declaring source. The bare-TYPE gate now resolves a
local only when the query originates in the local's own source (R2 preserved);
a same-name block-local of a DIFFERENT source routes to the undeclared path so
the leak surfaces (`unknown type '...'`, exit 1) instead of escaping via the
`registered` catch-all that would otherwise resolve the globally-registered
cross-source local.
Regression: examples/0762 — imported `Bad :: struct($T) { x: T; y: LocalOnly; }`
with `LocalOnly` declared only in the caller `main` now errors in lib.sx
(fail-before on 8162170 printed `1 9` exit 0).
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// An IMPORTED generic template's field that names a type the CALLER declared
|
||||
// only as a BLOCK-LOCAL must NOT bind that caller-local type — a block-local is
|
||||
// visible only within its OWN source. `lib.sx` defines
|
||||
// `Bad :: struct($T) { x: T; y: LocalOnly; }`; `main` declares `LocalOnly` only
|
||||
// inside its own body before instantiating `Bad(s32)`. The imported template's
|
||||
// module cannot see a caller block-local, so `y: LocalOnly` is undeclared in the
|
||||
// lib file.
|
||||
//
|
||||
// Before the fix the global `local_type_names` set was source-insensitive: the
|
||||
// template's field resolution (run in the template's source context, E3
|
||||
// attempt-4) consulted it, found the caller's `LocalOnly`, and silently compiled
|
||||
// (printed a value, exit 0). `local_type_names` is now keyed by declaring source,
|
||||
// so a cross-source block-local no longer leaks into another source's resolution.
|
||||
//
|
||||
// Expected: `error: unknown type 'LocalOnly'` pointing into lib.sx; exit 1.
|
||||
// Regression (stdlib E3 attempt-5).
|
||||
#import "modules/std.sx";
|
||||
#import "0762-modules-imported-generic-caller-local-field-leak/lib.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
LocalOnly :: struct { v: s32; }
|
||||
b : Bad(s32) = .{ x = 1, y = .{ v = 9 } };
|
||||
print("{} {}\n", b.x, b.y.v);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Flat-imported generic struct whose field `y: LocalOnly` names a type that is
|
||||
// declared only as a BLOCK-LOCAL in the CALLER (`main`). The template's fields
|
||||
// resolve in THIS module's source context (E3 attempt-4), and a block-local type
|
||||
// is visible only within its own source, so `LocalOnly` is genuinely undeclared
|
||||
// here — the source-aware leaf surfaces it instead of binding the caller's local.
|
||||
Bad :: struct($T: Type) {
|
||||
x: T;
|
||||
y: LocalOnly;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: unknown type 'LocalOnly'
|
||||
--> examples/0762-modules-imported-generic-caller-local-field-leak/lib.sx:8:8
|
||||
|
|
||||
8 | y: LocalOnly;
|
||||
| ^^^^^^^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user