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).
26 lines
1.2 KiB
Plaintext
26 lines
1.2 KiB
Plaintext
// 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;
|
|
}
|