microsoft / microsoft/TypeScript
Runtime error when a derived class has uninitialized decorated field and a constructor with nested super call
Abierto
@rbuckton ya está trabajando en esto.
Desde el 29/1/2024.
Needs Investigation
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 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
💻 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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.