[P2] Compiler: Array.prototype.flat reads arguments indices before evaluating depth

Aperta
#3,535 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp, typescript
Ambito
compilers

Direzione di ricerca

Start by reading the inline Array.prototype.flat dispatch and the mapped arguments changes in #3510; compare their evaluation order with JavaScript’s call argument evaluation. Compile the sample as an unchecked classic .js program using --no-tsconfig --noLib --verify and check the trace against Node v22.23.2. Done means the depth expression runs before indexed access, while the result remains 7.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

An indexed arguments accessor runs before the depth expression when compiled JavaScript invokes Array.prototype.flat.call. JavaScript evaluates the call arguments before entering the builtin.

function run(first) {
    const args = arguments;
    const trace = [];
    Object.defineProperty(args, "0", { get() { trace.push("index"); return 7; } });
    const result = Array.prototype.flat.call(args, (trace.push("depth expression"), 1));
    console.log(result.join(","), trace.join(","));
}
run(1);

Node v22.23.2 prints 7 depth expression,index. The compiler with the mapped arguments changes in #3510 prints 7 index,depth expression and passes full saved IL verification. Clean main at cabb41636 prints an empty result with depth expression, since the former arguments snapshot skipped indexed accessors entirely. Compile the sample as an unchecked classic .js program with --no-tsconfig --noLib --verify.

Inline flat prepares its array-like input before evaluating the depth expression. The mapped arguments work makes indexed accessors observable, which exposes this pre-existing dispatch order. Related to #3533, which covers duplicate length reads.

Lingua principale
C#
Stelle
156
Fork
4
Merge medio
15h 49m
PR unite (30g)
42

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nickna/SharpTS

Tutte le issue di nickna/SharpTS

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.