Files
scriptc/tests/corpus/2513-dyn-evolving-array-derived.ts
Chris Tate 64bcb304e2 Monomorphize evolved-any array methods on the value's handle element under --dynamic
- An evolving-any array (const fns = []; fns.push(() => 1)) lowers array<jsval> at its any[] declaration, but tsc's evolving-array analysis answers the pushed element type at later method calls, so the lowering handed monomorphized helpers a jsval-element receiver under a typed signature — the SC9001 validator ICE.
- lowerArrayMethodCall now adopts the receiver VALUE's element type when it is a jsval-element array, riding the explicit-any[] handle-element lowering; HOF callback lead params bind the handles via jsvalParamOverrides whatever the evolved contextual type spelled.
- Derived bindings keep the handle-element array instead of the evolved spelling: locals adopt the initializer's type in lowerVarDecl, and file-scope globals register the handle-element array for aliases and receiver-type-preserving chains (filter/slice/splice/concat) rooted at a registered one.
- concat over a handle-element receiver decides spread-vs-element by the argument VALUE's array-ness, exactly JS's IsArray, instead of the evolved checker spelling.
- Corpus fixtures 2510-2513 pin map, filter/forEach/some/every/findIndex, mixed push sites, and the slice/concat and function-scope derived shapes, byte-identical vs Node under --dynamic on both backends.
2026-07-23 17:01:32 -05:00

26 lines
818 B
TypeScript

// @dynamic
// Derived values of an evolving-`any` closure array, at file scope and in
// a function body: slice and concat preserve the handle-element array
// (JS's IsArray decides concat's spread over the VALUE, not the evolved
// checker spelling), and the function-scope filter result adopts the
// handle-element type through the local declaration.
const fns = [];
fns.push(() => 1);
fns.push(() => 2);
fns.push(() => 3);
const tail = fns.slice(1);
console.log(tail.length);
tail.forEach(fn => console.log(fn()));
const both = fns.concat(tail);
console.log(both.length);
console.log(both.map(fn => fn()));
function pick(limit: number) {
const cbs = [];
cbs.push(() => limit);
cbs.push(() => limit * 2);
const kept = cbs.filter(fn => fn() > limit);
return kept.map(fn => fn());
}
console.log(pick(4));