Skip to content

[Completion] Remove uses of unbounded generic types #79585

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
merged 4 commits into from
Feb 27, 2025

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Feb 24, 2025

Ensure we always produce bounded generic type annotations and contextual types. While here, also make sure we substitute the base type for nested type completions.

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -395,8 +395,7 @@ static TypeRelation calculateTypeRelation(Type Ty, Type ExpectedTy,

// Equality/Conversion of GenericTypeParameterType won't account for
// requirements – ignore them
if (!Ty->hasTypeParameter() && !ExpectedTy->hasTypeParameter() &&
!Ty->hasUnboundGenericType() && !ExpectedTy->hasUnboundGenericType()) {
if (!Ty->hasTypeParameter() && !ExpectedTy->hasTypeParameter()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also get rid of type parameters at some point too, in favor of the caller mapping the type into the correct environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup I'm leaving that for a future PR

Ensure we always produce bounded generic type annotations and
contextual types.
We allow the unqualifed use of the enclosing nominal type in a where
clause, but only when it isn't a nested type, e.g:

```
struct S<T> {
  typealias T = T
  struct R<U> {
    typealias U = U
  }
}
extension S where S.T == Int {}   // allowed
extension S.R where R.U == Int {} // not allowed
```

Tweak the completion logic such that we don't suggest the type for
the nested case, instead it must be qualified.
Ensure we call `getTypeOfMember` for nested nominals and typealiases.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please SourceKit stress test

@hamishknight hamishknight marked this pull request as ready for review February 25, 2025 14:53
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

LGTM. Some nice improvements in the tests as well 😄

@hamishknight
Copy link
Contributor Author

@swift-ci please SourceKit stress test

@hamishknight hamishknight merged commit 35f79e4 into swiftlang:main Feb 27, 2025
5 of 6 checks passed
@hamishknight hamishknight deleted the leaps-and-bounds branch February 27, 2025 12:38
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