Skip to content

[CodeCompletion] Don’t crash when completing in a parameter position that only constraints one of two primary associated protocol types #65847

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

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 10, 2023

When completing, we call getExistentialType on the contextual type to get a nice and concise description of the contextual parameter’s type that doesn’t contain archetypes and which we can also serialize into a USR so we are able to calculate type relations for code completion results from the code completion cache.

When completing in a position that has a contextual type which only constrains one of two primary associated protocol types, this fails because getExistentialType (which calls getDependentUpperBounds) tries to form a ParameterizedProtocolType, which fails since not all primary associated types have been constrained.

AFAICT the fix here is to just fall back to the default behavior of returning the plain protocol type instead of aborting.

rdar://108835466

…that only constraints one of two primary associated protocol types

When completing, we call `getExistentialType` on the contextual type to get a nice and concise description of the contextual parameter’s type that doesn’t contain archetypes and which we can also serialize into a USR so we are able to calculate type relations for code completion results from the code completion cache.

When completing in a position that has a contextual type which only constrains one of two primary associated protocol types, this fails because `getExistentialType` (which calls `getDependentUpperBounds`) tries to form a `ParameterizedProtocolType`, which fails since not all primary associated types have been constrained.

AFAICT the fix here is to just fall back to the default behavior of returning the plain protocol type instead of `abort`ing.

rdar://108835466
@ahoppen
Copy link
Member Author

ahoppen commented May 10, 2023

@swift-ci Please smoke test

Comment on lines +727 to +736
// If we have constrained all primary associated types, create a
// parameterized protocol type. During code completion, we might call
// `getExistentialType` (which calls this method) on a generic parameter
// that doesn't have all parameters specified, e.g. to get a consise
// description of the parameter type to the following function.
//
// func foo<P: Publisher>(p: P) where P.Failure == Never
//
// In that case just add the base type in the default branch below.
if (argTypes.size() == primaryAssocTypes.size()) {
Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis May 11, 2023

Choose a reason for hiding this comment

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

Note: This makes sense in general because this method is not guaranteed to return a supremum (existentials are not that expressive at least yet), and so does ArchetypeType::getExistentialType.

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