Skip to content

[Sema] Skip adding solutions to completion callback if needed #61162

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
Sep 19, 2022

Conversation

bnbarham
Copy link
Contributor

If CompletionContextFinder fails to find a CompletionNode, skip trying to filter and add solutions to the completion callback. This prevents an assertion/crash in filterSolutionsForCodeCompletion which assumes CompletionNode is non-null (either an expression or keypath).

Resolves rdar://99966094.

If `CompletionContextFinder` fails to find a `CompletionNode`, skip
trying to filter and add solutions to the completion callback. This
prevents an assertion/crash in `filterSolutionsForCodeCompletion` which
assumes `CompletionNode` is non-null (either an expression or keypath).

Resolves rdar://99966094.
@bnbarham bnbarham requested review from xedin and ahoppen September 16, 2022 18:45
@bnbarham
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

I see. The example here could be a function with multiple result builder arguments and code completion token located in the second one, right @ahoppen?

@bnbarham
Copy link
Contributor Author

@swift-ci please test macOS platform

@bnbarham bnbarham merged commit 81c3a11 into swiftlang:main Sep 19, 2022
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.

I don’t think suppressing the assertion is the correct fix here. If we can’t find the code completion context, there’s something fundamentally going wrong and I’d like to figure out what it is.

Also, you removed a few assertions that we are in a key path completion context where a few lines below, we are getting the key path completion component, which is pretty much guaranteed to cause issues down the line.

@bnbarham bnbarham deleted the result-builder-completion-skip branch September 20, 2022 16:09
@bnbarham
Copy link
Contributor Author

I don’t think suppressing the assertion is the correct fix here. If we can’t find the code completion context, there’s something fundamentally going wrong and I’d like to figure out what it is.

The other location filterSolutionsForCodeCompletion is called has:

  // If there was no completion expr (e.g. if the code completion location was
  // among tokens that were skipped over during parser error recovery) bail.

and so I was assuming there was a similar case here. If that's not the case and we should always have a context here then IMO we should add an assertion before the if (and keep the if so that only +Asserts fails). I'd rather bail here in the release case than crash.

Also, you removed a few assertions that we are in a key path completion context where a few lines below, we are getting the key path completion component, which is pretty much guaranteed to cause issues down the line.

These were just superfluous, the same assertion is in getKeyPathContainingCompletionComponent which is called directly after anyway.

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.

3 participants