Skip to content

[Completion] Type-check parent closures for local functions #77537

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 3 commits into from
Nov 12, 2024

Conversation

hamishknight
Copy link
Contributor

Local functions can capture variables from parent closures, so we need to make sure we type-check parent closures when doing completion in a local function. Ideally we ought to be able to be more selective about the elements of the parent closure that we type-check, but that's a more complex change I'm leaving as future work for now.

Resolves #77305

Avoid type-checking local decls and macros, the
type-checking here should instead be handled by
TypeCheckASTNodeAtLocRequest.
Really this applies to any capture, not just
`self`. Also refactor to make it clear that
parent closures and functions are really the only
cases that matter here.
Local functions can capture variables from parent
closures, so we need to make sure we type-check
parent closures when doing completion in a local
function. Ideally we ought to be able to be more
selective about the elements of the parent closure
that we type-check, but that's a more complex change
I'm leaving as future work for now.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please SourceKit stress test

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

Looks reasonable

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

LGTM

@hamishknight hamishknight merged commit 36a9628 into swiftlang:main Nov 12, 2024
6 checks passed
@hamishknight hamishknight deleted the complete-func branch November 12, 2024 10:40
if (!ctx.CompletionCallback) {
// Type-check any local decls encountered.
for (auto *D : LocalDeclsToTypeCheck)
TypeChecker::typeCheckDecl(D);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should skip adding them to the local decls and macro lists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I don't mind

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hamishknight added a commit to hamishknight/swift that referenced this pull request Nov 12, 2024
hamishknight added a commit that referenced this pull request Nov 13, 2024
SharonXSharon pushed a commit to SharonXSharon/swift that referenced this pull request Dec 13, 2024
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.

Completion doesn't work in nested function in closure
4 participants