You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Search Terms:
super, this and variations of "'super' must be called before accessing 'this' in the constructor of a derived class."
Code
exportclassFoo{constructor(value: number){}}exportclassBarCorrectlyFailsextendsFoo{constructor(something: boolean){if(!something){constvalue=this.bar();// <--- this used before super; correctly detectedsuper(value);}else{super(1337);}}bar(): number{return4;}}exportclassBarIncorrectlyWorksextendsFoo{constructor(something: boolean){if(something){super(1337);}else{constvalue=this.bar();// <--- this used before super; not detectedsuper(value);}}bar(): number{return4;}}
Expected behavior:
Both of the above Bar* classes should fail to compile. The branches seem to be ignored when determining if this and super are called in-order, so the above super call in another branch seems to allow compilation to continue.
Actual behavior:
The BarIncorrectlyWorks produces ESM code which fails at runtime, when the super occurs before the this.
The text was updated successfully, but these errors were encountered:
The issue here is our fairly naive check that first occurrence of a super call in lexical order occurs before every this member access. That check is really only correct when there are no branches in the code.
Search Terms:
super, this and variations of "'super' must be called before accessing 'this' in the constructor of a derived class."
Code
Expected behavior:
Both of the above
Bar*
classes should fail to compile. The branches seem to be ignored when determining ifthis
andsuper
are called in-order, so the abovesuper
call in another branch seems to allow compilation to continue.Actual behavior:
The
BarIncorrectlyWorks
produces ESM code which fails at runtime, when the super occurs before thethis
.The text was updated successfully, but these errors were encountered: