Check using "super" before "this" lexically#6860
Merged
Merged
Conversation
added 3 commits
February 2, 2016 16:31
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
Member
There was a problem hiding this comment.
getSuperCallInConstructor
Contributor
Author
|
@DanielRosenwasser @vladima Any more comments? |
| } | ||
| } | ||
|
|
||
| function isSuperCallExpression(n: Node): boolean { |
Member
There was a problem hiding this comment.
This function already exists elsewhere, so you can remove this one.
| if (baseConstructorType === nullType) { | ||
| if (getSuperCallInConstructor(node)) { | ||
| if (classExtendsNull) { | ||
| error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null); |
Member
There was a problem hiding this comment.
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.
Contributor
|
👍 |
Contributor
|
Please port this to master as well. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
iwhich then try to go resolveswhich causecheckThisExpressionto be called before theNodeCheckFlags.HasSeenSuperCallis set.@ahejlsberg suggests a new approach to check if
superis called beforethislexically. 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