Skip to content

Sema: Fix two bugs with type resolution of generic arguments [5.10] #69129

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

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Oct 11, 2023

  • Description: When resolving the generic argument list of a generic type, we didn't check for certain invalid situations involving occurrences of pack expansion types. As a result we would crash instead of producing a diagnostic.
  • Risk: Very low. (Note: The middle commit is a refactoring that has been on main for a while. I cherry-picked it to avoid merge conflicts)
  • Tested: New test cases added.
  • Radar: rdar://116713961 and rdar://116716014.
  • Reviewed by: @hborla

Applying generic arguments to a variadic generic type uses the
PackMatcher to build a mapping between generic parameters and
arguments.

The PackMatcher is symmetric, so there was an unexpected failure
mode that wasn't handled: if the variadic generic type had some
non-pack parameters, but the argument list was a single pack
expansion type, the match would succeed, grouping all of the
generic parameters into a single match.

This is non-sensical, so we need to explicitly check for this
case and diagnose it. This requires a new diagnostic, since
otherwise the general diagnostic we emit for variadic generic
type mismatches doesn't make sense, since it's complaining
about there being too few generic parameters.

Fixes rdar://116713961 / swiftlang#69012.
…ons, and reject pack expansion types there

We used to disallow pack expansions in generic argument lists of
protocols, but allow them for all other nominal types. However,
we only actually checked that the pack expansions match up if
the type itself was variadic.

Fix this by repurposing Context::ProtocolGenericArgument into
Context::ScalarGenericArgument, and using that when the type does
not have a parameter pack.

Context::GenericArgument is now Context::VariadicGenericArgument,
and we only use it if the type has a parameter pack, in which case
we use the PackMatcher, so any pack expansions in the wrong place
are caught there.

Fixes rdar://116716014 and swiftlang#69088.
@slavapestov slavapestov requested a review from a team as a code owner October 11, 2023 14:49
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 3b81d27 into swiftlang:release/5.10 Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants