Error on accessing private property through destructuring assignment, and mark property used#26381
Merged
2 commits merged intomasterfrom Aug 13, 2018
Merged
Conversation
… and mark property used
66dc4ee to
774c6be
Compare
sandersn
approved these changes
Aug 13, 2018
| * @param type The type of the object whose property is being accessed. (Not the type of the property.) | ||
| * @param prop The symbol for the property being accessed. | ||
| */ | ||
| function checkPropertyAccessibility(node: PropertyAccessExpression | QualifiedName | VariableLikeDeclaration | ImportTypeNode, left: Expression | QualifiedName | ImportTypeNode, type: Type, prop: Symbol): boolean { |
Member
There was a problem hiding this comment.
Just checking: are the changes to this function just cleanup or do they actually fix one of the bugs?
Author
There was a problem hiding this comment.
One of the parameters changed. We no longer pass in the LHS (since destructuring doesn't have one), we just pass in whether it's a super. access.
src/compiler/checker.ts
Outdated
| else { | ||
| // non-shorthand property assignments should always have initializers | ||
| return checkDestructuringAssignment(property.initializer, type); | ||
| let type: Type | undefined; |
Member
There was a problem hiding this comment.
Might be worth extracting this to a function? I think it’s self-contained.
src/compiler/checker.ts
Outdated
| const prop = getPropertyOfType(objectLiteralType, text); | ||
| if (prop) { | ||
| markPropertyAsReferenced(prop, property, rightIsThis); | ||
| checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop); |
Member
There was a problem hiding this comment.
Should you be getting type only if propertyAccessibility doesn't have issues?
Author
There was a problem hiding this comment.
It looks like we normally just call this for the diagnostic and don't change the type, e.g.:
class C { private x!: number; }
const x = new C().x; // Error, but doesn't affect type
x; // number
sheetalkamat
approved these changes
Aug 13, 2018
This pull request was closed.
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.
Fixes #26355 and #26380
Discovered but did not fix #26379