Files
scriptc/tests/diagnostics/unmappable-declaration-initializer.ts
T
Malte UblandClaude Opus 5.5 caf098eff9 Refuse a stdlib-global snapshot read as a value
`const proc = globalThis.process` lowers to alias plumbing: the declaration
emits no storage and no code, because member and call reads resolve through
the global it names. A read that needs the VALUE therefore failed at the use
with the generic "binding form with no lowering", which names neither the
declaration nor the cause.

Register every stdlib-global snapshot declaration (TypeScript sources only,
matching the elision) and report the cause at the declaration (SC2020),
naming the global and, when it has a short spelling, the type the program
asked the compiler to hold. The use site keeps the inherited-blocker cascade
(SC2004) instead of the generic text.

An unread snapshot stays elided: reading a global has no side effects, so
dropping an unread `const p = process` is observationally identical to Node,
and refusing it would break programs that compile harmlessly today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 17:58:04 -07:00

11 lines
365 B
TypeScript

// An initializer is never dropped. This declaration's type has no lowering,
// so the declaration is refused where it is written — it cannot compile away
// with the call in its initializer, which would run under Node.
function touch(): number {
return 1;
}
function run(): void {
const ref: WeakRef<object> = touch() as unknown as WeakRef<object>;
}
run();