Files
scriptc/tests/diagnostics/function-forms.ts
T
Malte UblandClaude Opus 5.5 ac2323fb2a Retire the spread diagnostics fixtures their corpus programs replace
`tests/diagnostics/spread-fences.ts` pinned the conditional-spread fence
(`...(c ? { x: 1, y: 2 } : { x: 3, y: 4 })`) and
`spread-runtime-optional.ts` pinned the `{ ...value }` spread over a
callback's runtime-optional record. Both shapes compile now, so neither
file can stay in a suite whose contract is that every program in it fails;
the differential corpus owns them instead (`8501-object-spread-optional-source`,
`8503-object-spread-conditional-shapes`), where the programs run under Node
and as a compiled binary rather than pinning a refusal.

The rest of `spread-fences.ts` already compiled before this branch, and the
fences it named that remain (an element-type mismatch, a non-tuple call
spread) are ordinary type errors, so the file goes with the fence it pinned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 09:37:13 -07:00

55 lines
2.0 KiB
TypeScript

// Overload signatures compile now (they lower to nothing; calls flow
// through the implementation's ABI — corpus 1850/1851); kept here as
// working context for the fences below.
function overloaded(a: number): number;
function overloaded(a: string): string;
function overloaded(a: number | string): number | string {
return a;
}
// Type-parameter defaults compile now (bindings fill from the mapped
// default — corpus 1950); kept as working context for the fences below.
function defaulted_tp<T = number>(x: T): T {
return x;
}
console.log(defaulted_tp(1));
// Optional/default/rest parameters compile for direct calls. Typed rest
// functions are first-class values too; the remaining fence below is for a
// nested defaulted declaration with no contextual completed signature.
function optional(a?: number): number {
return a === undefined ? 0 : a;
}
function defaulted(a: number = 1): number {
return a;
}
function rest(...args: number[]): number {
return args.length;
}
// Optional/defaulted functions as values compile when the inferred binding
// spells the completed `T | undefined` signature (corpus 1535); typed rest
// signatures carry a packed-array ABI (corpus 2917).
const restRef = rest;
// Union-typed parameter defaults compile now (corpus 1535); kept here as
// working context for the fences below.
function unionDefault(x: string | null = "hi"): void {
console.log(x === null);
}
// Nested function declarations are values (const name = lambda) — fenced.
function outer(): number {
function inner(n = 2): number {
return n;
}
return inner(1) + inner();
}
// Spread into a REST parameter lowers (the pack copies the spread's
// elements); the object and array spread shapes are covered by the
// differential corpus.
const pair = [1, 2];
console.log(rest(...pair));
unionDefault();
console.log(optional(1), defaulted(), rest(1, 2), outer());
// Reached: collection defers its diagnostics until a reference makes
// them relevant; these references are what makes them count.
overloaded(1);
defaulted_tp(1);