Skip to content

[AST] Don't suggest unusable values for typo correction and code completion #20904

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

Merged
merged 1 commit into from
Dec 4, 2018

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Nov 30, 2018

Filter out:

  • use within its own initial value
  • use before declaration for local values

rdar://problem/25068938

@rintaro rintaro requested a review from benlangmuir November 30, 2018 04:55
@rintaro
Copy link
Member Author

rintaro commented Nov 30, 2018

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Nov 30, 2018

Supersedes #20677.

@benlangmuir
The logic shared with "use before declaration" diagnostics was FindLocalVal.
Since I implemented filter in lookupVisibleDecls(), we don't need to add any flag because all clients of it (code-completion, typo-correction, and refactoring) want "usable" values only.

Copy link
Contributor

@benlangmuir benlangmuir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my comment about naming, LGTM.

SourceLoc Loc;
VisibleDeclConsumer &Consumer;

bool checkLocalValue(ValueDecl *VD, DeclVisibilityKind Reason) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this to something that makes it clear what true and false return values mean - e.g. isUsableLocalValue.


switch (Reason) {
case DeclVisibilityKind::LocalVariable:
// Use 'TypeDecl's before declaration is allowed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Use of

@jrose-apple
Copy link
Contributor

@DougGregor may also have opinions here from his work on ASTScope. (Specifically, lookupVisibleDecls isn't supposed to produce these invalid values in the first place.)

@rintaro rintaro force-pushed the ast-lookupvisibledecls-forward branch from d417025 to 1f17088 Compare December 2, 2018 00:32
…letion

Filter out these cases:

- use within its own initial value
- use before declaration for local values

rdar://problem/25068938
@rintaro rintaro force-pushed the ast-lookupvisibledecls-forward branch from 1f17088 to a54d2ff Compare December 2, 2018 00:33
@rintaro
Copy link
Member Author

rintaro commented Dec 2, 2018

@swift-ci Please smoke test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good direction. It's what ASTScope would naturally do, but we don't want to wait for ASTScope.

@rintaro rintaro merged commit ba0e575 into swiftlang:master Dec 4, 2018
@rintaro rintaro deleted the ast-lookupvisibledecls-forward branch December 4, 2018 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants