-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check using "super" before "this" lexically #6860
Conversation
add baselines Update baseline
NodeCheckFlags Remove "type-checking" way of checking if super is used before this. Instead check using whether super occurs before this syntactically Refactor the code Dive down to get super call
* | ||
* @param constructor constructor-function to look for super statement | ||
*/ | ||
function getSuperStatementInConstructor(constructor: ConstructorDeclaration): ExpressionStatement { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getSuperCallInConstructor
@DanielRosenwasser @vladima Any more comments? |
@@ -7306,6 +7306,50 @@ namespace ts { | |||
} | |||
} | |||
|
|||
function isSuperCallExpression(n: Node): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function already exists elsewhere, so you can remove this one.
if (containsSuperCall(node.body)) { | ||
if (baseConstructorType === nullType) { | ||
if (getSuperCallInConstructor(node)) { | ||
if (classExtendsNull) { | ||
error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently you're erroring on the constructor node itself, which gives a pretty unpleasant experience (it errors on the entire body as well).
You should report an error on the super call that you were able to find.
👍 |
Please port this to master as well. |
Check using "super" before "this" lexically
Update baselines add baselines Update baseline Port PR #6860 lexically check calling super before this Check using "super" before "this" lexically instead of using the NodeCheckFlags Remove "type-checking" way of checking if super is used before this. Instead check using whether super occurs before this syntactically Refactor the code Dive down to get super call Address PR Address PR about tests Add a flag so we don't repeatedly finding super call rename function Move tests into correct location Address PR: report error on super call instead of entire constructor node remove marge mark
Changes Unknown when pulling 61e954b on checksuperbeforethislexically into ** on release-1.8**. |
@coveralls why are you here? |
With previous approach @ahejlsberg pointed out, it fails in the following case
This behavior is due to the fact that when the compiler is in the middle of checking super, it will then go and try to resolve
i
which then try to go resolves
which causecheckThisExpression
to be called before theNodeCheckFlags.HasSeenSuperCall
is set.@ahejlsberg suggests a new approach to check if
super
is called beforethis
lexically. This approached will be more robust against type-checker diving down when type-checking particular statement.The fix also includes not-erroring when extends null as pointed out by @rbuckton