Skip to content

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

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

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 16, 2023

  • Explanation: 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.
  • Scope: Anything that calls ArchetypeType::getExistentialType, which isn’t very narrowly-scoped
  • Risk: Very low, we were always aborting in this before
  • Testing: Added test case
  • Issue: rdar://108835466
  • Reviewer: @slavapestov on [CodeCompletion] Don’t crash when completing in a parameter position that only constraints one of two primary associated protocol types #65847

…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 ahoppen requested a review from a team as a code owner May 16, 2023 00:11
@ahoppen ahoppen changed the title [CodeCompletion] Don’t crash when completing in a parameter position that only constraints one of two primary associated protocol types [5.9][CodeCompletion] Don’t crash when completing in a parameter position that only constraints one of two primary associated protocol types May 16, 2023
@ahoppen ahoppen added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 labels May 16, 2023
@ahoppen
Copy link
Member Author

ahoppen commented May 16, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 25, 2023

@swift-ci Please test macOS

@ahoppen
Copy link
Member Author

ahoppen commented May 25, 2023

Fix already cherry-picked as part of #66017

@ahoppen ahoppen closed this May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant