Static field initialization flow treats an undefined assignment as initialized

Aperta
#3,637 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
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp, typescript
Ambito
compilers

Direzione di ricerca

The check lives in the static initializer analysis that tracks fields assigned through a preceding static block, referenced as #3621; locate it in the type checker and find where a field's assigned value is recorded. The failing case is a static block assigning undefined to a field typed number | undefined, followed by a static field reading this.value, which should not be flagged as used before initialization. Done when the snippet compiles with --strict --noEmit and matches TypeScript's TS2729 behavior for the undefined-valued case.

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

Descrizione

class C {
    static value: number | undefined;
    static { this.value = undefined; }
    static read = this.value;
}

SharpTS accepts this with --no-tsconfig --strict --noEmit. TypeScript 6.0.3 reports TS2729 at this.value with --ignoreConfig --strict --target ES2022 --noEmit.

The static initializer check from #3621 tracks which fields were assigned on all paths through a preceding static block. For a type that includes undefined, it also needs to account for the assigned value. Found while verifying the CI fix for #3636.

Lingua principale
C#
Stelle
156
Fork
4
Merge medio
16h 37m
PR unite (30g)
41

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.