Skip to content

Conversation

@xedin
Copy link
Contributor

@xedin xedin commented Jun 28, 2023

  • Teach specialization constraint to look through non-generic typealiases
  • Detect and diagnose attempts to specialize non-generic types/aliases
  • Detect and diagnose attempts to specialize types with invalid number of arguments

Resolves: rdar://111239949

xedin added 8 commits June 27, 2023 17:24
…ric typealiases

If type alias declaration doesn't add new generic parameters
refer to its underlying type to find them.
…ete type

Diagnose attempts to specialize a concrete type or its alias:

```swift
struct Test {}
typealias X = Test

_ = X<Int>() // error
```
The situations where number of parameters and arguments didn't match.
…f generic arguments

```swift
struct Test<T, U> {}
_ = Test<Int>() // error
```
@xedin xedin requested a review from hborla as a code owner June 28, 2023 00:25
@xedin
Copy link
Contributor Author

xedin commented Jun 28, 2023

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jun 28, 2023

@swift-ci please clean test macOS platform

return nullptr;

auto genericParams = genericContext->getGenericParams();
if (!genericParams || genericParams->size() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you can have a non-null generic parameter list with zero parameters in it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the original check but I can simplify it down to just !genericParams

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

if (auto *TA = dyn_cast<TypeAliasDecl>(decl)) {
if (TA->isGeneric())
return nullptr;
if (auto underlying = TA->getUnderlyingType()->getAnyNominal())
Copy link
Contributor

Choose a reason for hiding this comment

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

How about checking if TA->getUnderlyingType()-is<UnboundGenericType>()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other places I saw check for isGeneric but I can change if that’s better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@slavapestov I made it AnyGenericType to make it possible to properly diagnose cases like typealias Print = Printer<Any>, using UnboundGenericType won't work because we'd just return nullptr and following logic would just return SolutionKind::Solved and I don't want to mess with that in this PR.

@xedin
Copy link
Contributor Author

xedin commented Jun 29, 2023

@swift-ci please test

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