mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +08:00
- 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.
19 lines
660 B
TypeScript
19 lines
660 B
TypeScript
// @dynamic
|
|
// Mixed push sites on an evolving-`any` closure array: the SECOND push
|
|
// happens after tsc's flow analysis evolved the receiver past `any[]` to
|
|
// the pushed element type, so the push argument marshals into the handle
|
|
// element slot like the first one did. Loop-pushed closures capture their
|
|
// iteration binding; the arity-2 map callback receives (element, index).
|
|
const fns = [];
|
|
fns.push(() => 1);
|
|
fns.push(() => 2);
|
|
for (let i = 0; i < 2; i++) {
|
|
fns.push(() => 10 + i);
|
|
}
|
|
console.log(fns.length);
|
|
const doubled = fns.map((fn, i) => fn() + i);
|
|
console.log(doubled);
|
|
let total = 0;
|
|
fns.forEach(fn => { total += fn(); });
|
|
console.log(total);
|