Skip to content

[5.7][LookupVisibleDecls] Implement shadowing for unqualified lookups #58530

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

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Apr 29, 2022

Cherry-pick #58512 into release/5.7

  • Explanation: lookupVisibleDecls() function used by code completion is supposed to return all visible and usable declarations. It used to have several issues, such as local types/funcs declared after the code completion point weren't reported despite they are usable, unusable instance members in outer type context were reported, unusable local values outside the current type context were reported, and the name shadowing wasn't implemented. Especially, the lack of shadowing results duplicated code completion entries, for example, in if let user = user { <HERE> }, both the outer user: User? and the inner user: User were reported, which was confusing. This change resolves those issues, so that code completion can provide more accurate results.
  • Scope: Non-member code completion (i.e. code completion at primary-expression and type-identifier)
  • Risk: Low. This doesn't affect compilation
  • Issues: rdar://86285396
  • Testing: Added regression test cases
  • Reviewer: Slava Pestov (@slavapestov)

@rintaro rintaro requested a review from a team as a code owner April 29, 2022 17:01
@rintaro
Copy link
Member Author

rintaro commented Apr 29, 2022

@swift-ci Please test

Tweaked usable check:
  * Local type/func decls are usable even before declaration
  * Outer nominal Instance member are not usable
  * Type context cannot close over values in outer type contexts

Added shadowing rule by the base name:
  * Type members don't shadow each other as long as they are in the
    same type context.
  * Local values shadow everything in outer scope
    * Except that 'func' decl doesn't shadow 'var' decl if they are in the
      same scope.

rdar://86285396
(cherry picked from commit eade9b7)
@rintaro rintaro force-pushed the 5.7-ide-completion-shadowing-rdar86285396 branch from 9a48d05 to 1f56100 Compare April 29, 2022 18:04
@rintaro
Copy link
Member Author

rintaro commented Apr 29, 2022

@swift-ci Please test

@rintaro rintaro merged commit 96c7e81 into swiftlang:release/5.7 May 6, 2022
@rintaro rintaro deleted the 5.7-ide-completion-shadowing-rdar86285396 branch May 6, 2022 17:23
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.

2 participants