microsoft / microsoft/TypeScript

Runtime error when a derived class has uninitialized decorated field and a constructor with nested super call

Aperta
#57,212 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@rbuckton ci sta già lavorando.

Dal 29/1/2024.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

decorator, initializer, constructor, super call

🕗 Version & Regression Information
  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried (after ES decorators are implemented), and I reviewed the FAQ for entries about decorators
  • I was unable to test this on prior versions because _______
⏯ Playground Link

https://www.typescriptlang.org/play?useDefineForClassFields=true&target=9&ts=5.4.0-dev.20240129#code/MYGwhgzhAEAiCmAnAlgN3gE2vAHgF3gDsMZRIYBvAX2goChpoABACgDMBXQ4PZAe0IsA+gBpowAQXwBKWg0bjJuPADowGDAElCyXmBDIAXknZce-QbPoKFeABbIIKtnz7QAvNAAMAbnmMqaXlA+Rc+AC5oMEIATz9GCUIIPEQOHj5EFit-aFQwRGgAI0h4D2gIDgAHE2l46Co6BrpEiD4QeBUQPgBzFkJ4AHc4JDRMLOdXaSA

💻 Code
class Derived extends class {} {
  @(function(_, context) {
    context.addInitializer(function() {
      this.foo = 0;
    })
  })
  foo: any;
  constructor() {
    var base = super();
  }
}

console.log(new Derived().foo)
🙁 Actual behavior

Runtime error: Must call super constructor in derived class before accessing 'this' or returning from derived constructor

The generated code inserts __runInitializers calls before the nested super call. It seems that the transformer only searches top level super calls. We should probably traverse the constructor node.

🙂 Expected behavior

It should print 0

Additional information about the issue

No response

Guida per i contributori

Apri la guida per i contributori

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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.