-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[code-completion] Fix assertion failure in getValueExprCompletions #15471
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
[code-completion] Fix assertion failure in getValueExprCompletions #15471
Conversation
f49a1c6
to
360f68d
Compare
@swift-ci please test |
Build failed |
@swift-ci please smoke test os x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If given a function type, it would add function call completions, set Done=true, and then eventually progress to some logic intended to add completions for the unwrapped type of optionals without checking Done. That code would check if the corresponding Decl has the IUO attribute set and, if it was but couldn't be unwrapped, assert.
When would it have IUO set? When the return type is IUO?
I refactored this to early exit rather than set and check Done, since each special case seems mutually exclusive.
Thanks, this bit is much easier to understand now.
@benlangmuir, that's right. I'll update the commit message/PR description to clarify, but were there any follow-up comments/issues before I do? |
lib/IDE/CodeCompletion.cpp
Outdated
@@ -1734,6 +1735,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer { | |||
this->DotLoc = DotLoc; | |||
} | |||
|
|||
void setIsUnwrapped(bool value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: could we please call this setIsUnwrappedOptional
? Otherwise LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. Thanks!
This was caused by two separate issues: 1. If given a function type with an IUO return, it would add function call completions, set Done=true, and then progress to some logic to add completions for the unwrapped type of optionals. That code would check if the corresponding decl has the IUO attribute set and, if it was but couldn't be unwrapped, assert. For function types, it now early exits after adding call completions. 2. If given the type of a bound (`blah?.`) or forced (`blah!.`) optional, the type is non-optional and can't be unwrapped and the decl still has the IUO so it asserts. Refined the assertion to account for this case. Resolves rdar://problem/38188989.
360f68d
to
d4bd291
Compare
@swift-ci please smoke test and merge |
@swift-ci Please smoke test |
This was caused by two separate issues:
If given a function type, it would add function call completions, set
Done=true
, and then eventually progress to some logic intended to add completions for the unwrapped type of optionals without checkingDone
. That code would check if the corresponding Decl has the IUO attribute set and, if it was but couldn't be unwrapped, assert. I refactored this to early exit rather than set and checkDone
, since each special case seems mutually exclusive.If the base is a bound (
blah?.
) or forced (blah!.
) optional, the type passed is non-optional so can't be unwrapped and the Decl still has the IUO attribute so it hits the same assertion failure. Refined the assertion to account for this case.Resolves rdar://problem/38188989