Skip to content

[5.9][CodeCompletion] Fix a crash when completing an argument to a function taking a parameter pack #65771

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 8, 2023

  • Explanation: We previously asserted that for a call the function type had the same number of parameters as the declaration. But that’s not true for parameter packs anymore because the parameter pack will be exploded in the function type to account for passing multiple arguments to the pack.
    To fix this, use ConcreteDeclRef instead of a ValueDecl, which has a substitution map and is able to account for the exploded parameter packs when accessed using getParameterAt.
  • Scope: Code completion of arguments
  • Risk: 2/5
  • Testing: Added regression test
  • Issue: rdar://100066716
  • Reviewer: @xedin and @rintaro on [CodeCompletion] Fix a crash when completing an argument to a function taking a parameter pack #65720

…n taking a parameter pack

We previously asserted that for a call the function type had the same number of parameters as the declaration. But that’s not true for parameter packs anymore because the parameter pack will be exploded in the function type to account for passing multiple arguments to the pack.

To fix this, use `ConcreteDeclRef` instead of a `ValueDecl`, which has a substitution map and is able to account for the exploded parameter packs when accessed using `getParameterAt`.

rdar://100066716
@ahoppen ahoppen added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 labels May 8, 2023
@ahoppen ahoppen requested a review from a team as a code owner May 8, 2023 17:54
@ahoppen
Copy link
Member Author

ahoppen commented May 8, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 10, 2023

@swift-ci Please test macOS

Whe completing in parameter packs, we were calling `getParameterAt` with `Res.FuncDeclRef`. But the substitution map in `Res.FuncDeclRef` contained type variables that were allocated in the constraint system’s arena. And that arena had been freed when we call this from `deliverResults`.

The fix is to compute the optional parameters in advance in `sawSolutionImpl`

rdar://109093909
@ahoppen
Copy link
Member Author

ahoppen commented May 12, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 14, 2023

@swift-ci Please test Linux

@ahoppen ahoppen merged commit e13fe5b into swiftlang:release/5.9 May 15, 2023
@ahoppen ahoppen deleted the ahoppen/5.9/complete-parameter-pack-arg branch May 15, 2023 22:17
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.

2 participants