Files
scriptc/tests/corpus/optional-call-library-function.ts
T
Malte UblandClaude Opus 5.5 0260725265 Fold the optional-call guard on a never-nullish library function
`rmSync?.(…)`: an imported node:fs function has a call lowering but no
value form, so lowering the guarded callee failed with "library
functions as values". The checker types the callee never-nullish, so the
guard can never short-circuit and the step is the plain call. When the
callee is never-nullish (any/unknown excluded) and has no value
lowering, mark the call's `?.` node chainHandled and re-dispatch the
plain call; it reports its own diagnostics when it has no lowering
either.

Also drops the unused isSafeToDiscard import left behind in
optional-chains.ts. Corpus: tests/corpus/optional-call-library-function.ts
(Node vs native, byte-identical).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 06:45:46 -07:00

28 lines
1019 B
TypeScript

// `f?.(…)` where the checker types the callee never-nullish: an imported
// node:fs function has no value form at all (only a call), and the guard
// can never short-circuit, so the step is the plain call. The present
// target is created and removed; the force-missing target stays silent,
// exactly as the plain call.
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
const base = mkdtempSync(join(tmpdir(), "scriptc-optcall-"));
const dir = join(base, "nested");
rmSync?.(dir, { force: true, recursive: true });
mkdirSync(dir, { recursive: true });
console.log("created");
rmSync?.(dir, { force: true, recursive: true });
console.log("removed");
rmSync?.(join(base, "missing"), { force: true, recursive: true });
console.log("missing ok");
// The plain spelling of the same import keeps compiling unchanged.
rmSync(dir, { force: true, recursive: true });
console.log("plain ok");
rmSync?.(base, { force: true, recursive: true });