Files
scriptc/tests/diagnostics/tuples.ts
Chris Tate 7c93ab6505 Console prints every inspectable shape with Node's console semantics
- console.log/info/debug/error/warn take unknown[] and render every non-scalar argument through the static util.inspect at the rest-args depth 2, strings verbatim
- top-level unions dispatch per arm at runtime with string arms raw, and util.format's %s/rest args take the same per-arm rule
- info and debug lower as stdout aliases of log; the remaining stock console members are declared in the fallback so stock-clean programs meet per-site SC2020 hints instead of a fallback-manufactured SC0001
- corpus 2440/2441 pin the widened shapes on both backends, console.log(process.argv), a find() miss union, and console.log(undefined) included
- diagnostics snapshots re-pinned: the union console fences retire and utility-types reports its real per-site fences
2026-07-23 01:28:47 -05:00

42 lines
1.5 KiB
TypeScript

// Tuple + ref-element-array fences — what stays OUT of the new surface and
// why: dynamic tuple indexing (heterogeneous positions have no single
// element type), optional/rest tuple elements (no fixed shape), for-of over
// tuples, spread into tuple literals, join on ref-element arrays (JS would
// recursively toString), and Map-element arrays (hashed storage has no
// element representation in the array runtime).
const pair: [string, number] = ["a", 1];
// Dynamic index: reads and writes both need the literal-index shape.
let i = 0;
console.log(pair[i]);
pair[i] = "b";
// Optional and rest elements have no fixed arity/shape.
const opt: [string, number?] = ["x"];
const rest: [string, ...number[]] = ["y", 1, 2];
// Heterogeneous tuples ITERATE now (positions snapshot into the union),
// and the union-typed loop variable PRINTS (per-arm console rendering).
for (const part of pair) {
console.log(part);
}
// Spread has no fixed positions inside a tuple literal.
const copy: [string, number] = [...pair];
// The arity constant folds only off side-effect-free receivers.
function mk(): [string, number] {
return ["z", 9];
}
console.log(mk().length);
// join on ref-element arrays: JS would recursively toString — dishonest.
const recs: { id: number }[] = [{ id: 1 }];
console.log(recs.join(","));
const tuples: [string, string][] = [["k", "v"]];
console.log(tuples.join(";"));
// Map elements stay out entirely (function elements compile — the REF
// element kind).
const maps: Map<string, number>[] = [];