Skip to content

[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

Conversation

nathawes
Copy link
Contributor

This was caused by two separate issues:

  1. 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. I refactored this to early exit rather than set and check Done, since each special case seems mutually exclusive.

  2. 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

@nathawes nathawes force-pushed the rdar38188989-code-completion-assertion-failure-in-getValueExprCompletions branch from f49a1c6 to 360f68d Compare March 24, 2018 01:00
@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes requested a review from benlangmuir March 24, 2018 01:01
@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 360f68d91e62c4ec29bf3a98e21bdbbce0a32069

@nathawes
Copy link
Contributor Author

@swift-ci please smoke test os x

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.

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.

@nathawes
Copy link
Contributor Author

@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?

@@ -1734,6 +1735,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
this->DotLoc = DotLoc;
}

void setIsUnwrapped(bool value) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.
@nathawes nathawes force-pushed the rdar38188989-code-completion-assertion-failure-in-getValueExprCompletions branch from 360f68d to d4bd291 Compare March 26, 2018 18:13
@nathawes
Copy link
Contributor Author

@swift-ci please smoke test and merge

@nathawes
Copy link
Contributor Author

@swift-ci Please smoke test

@nathawes nathawes merged commit cc02728 into swiftlang:master Mar 26, 2018
@nathawes nathawes deleted the rdar38188989-code-completion-assertion-failure-in-getValueExprCompletions branch March 26, 2018 20:47
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