microsoft / microsoft/TypeScript

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

オープン
#57,212 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

@rbuckton がすでに取り組んでいます。

2024年1月29日 から。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。