Files
scriptc/tests/corpus/1871-empty-array-never.ts
Jimmy Miller 522e841fd8 Add sparse array support
Represent array holes independently from element storage with an optional runtime presence bitmap. Preserve hole state through length changes, deletion, slicing, concatenation, sorting, copying methods, iteration, serialization, and reference-counted cleanup while retaining packed-array fast paths.

Extend frontend lowering and IR validation for sparse literals, Array length construction, property-presence checks, delete, length assignment, and sparse appends. Add dense-array analysis so proven packed reads can use dedicated unchecked-presence runtime entry points in both native backends.

Add differential corpus coverage, runtime lifecycle tests, IR analysis tests, and compile fences for JavaScript fill loops that cannot prove complete initialization. Update affected binary-size expectations and align structuredClone transfer diagnostics with Node wording.
2026-08-03 15:34:20 -04:00

32 lines
1.1 KiB
TypeScript

// The empty array literal and `never`: `[]` with no contextual type infers
// never[], whose element type is uninhabited — the representation is
// unobservable, so the array maps (f64 elements) and every use is the
// empty-array behavior Node has.
// for-of over a literal []: zero iterations, loop var typed never.
for (const x of []) {
console.log(x);
}
console.log("after-empty-loop");
// An empty literal bound and read: length, includes-style emptiness.
const none = [] as never[];
console.log(none.length);
// An empty literal against a union slot still builds the ARM's element
// type (the contextual-union rule), not the never representation.
const s: string[] | undefined = [];
console.log(JSON.stringify(s));
// Sparse literals retain a distinct hole while their backing undefined arm
// makes length and indexed reads answer exactly Node.
var v1 = [,];
console.log(v1.length);
console.log(v1[0] === undefined);
var v2 = [, ,];
console.log(v2.length);
// An explicit undefined[] annotation with spelled-out elements.
const us: undefined[] = [undefined, undefined];
console.log(us.length, us[1] === undefined);