Skip to content
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

[Sema] Allow extending specialized types #39307

Closed

Conversation

Azoy
Copy link
Contributor

@Azoy Azoy commented Sep 14, 2021

While we patiently wait for parameterized extensions, I figured this feature can be split off and proposed separately so that people can use some much needed sugar for extensions. This allows for the following:

extension Array<Int> {} // translates to `extension Array where Element == Int {}`

This means that users can now finally use type sugar for their extended types like the following:

extension [Character] {
  func makeString() -> String {
    // ...
  }
}

In the process of doing this, I stumbled upon https://bugs.swift.org/browse/SR-4875 , and removing the constrained extension diagnostic means that this bug should probably just be fixed, so it is now.

Resolves: https://bugs.swift.org/browse/SR-4875

@Azoy Azoy requested review from slavapestov and CodaFi September 14, 2021 19:05
@Azoy
Copy link
Contributor Author

Azoy commented Sep 14, 2021

@swift-ci please test

@Azoy Azoy changed the title Allow extending specialized types [Sema] Allow extending specialized types Sep 14, 2021
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 418af510ffedeee9eeffab4efa732168f46d1fcd

@CodaFi
Copy link
Contributor

CodaFi commented Sep 14, 2021

@swift-ci clean test Linux

@CodaFi
Copy link
Contributor

CodaFi commented Sep 14, 2021

Looks like requirement_inference.swift needs updating as well.

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

Brilliant 👍

Does this need to go through evolution?

@AnthonyLatsis
Copy link
Collaborator

🎉

Does this need to go through evolution?

Speaking of which, I remember some people were sceptic about this because it wasn't obvious to them whether Array<Class> would translate to == or :.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 418af510ffedeee9eeffab4efa732168f46d1fcd

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 418af510ffedeee9eeffab4efa732168f46d1fcd

remove hacks for typealiases

remove isPassThroughTypealias
@Azoy Azoy force-pushed the extending-specialized-types-nonsense branch from 418af51 to db2f077 Compare September 15, 2021 19:53
@Azoy
Copy link
Contributor Author

Azoy commented Sep 15, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - db2f077

@Azoy
Copy link
Contributor Author

Azoy commented Sep 15, 2021

@swift-ci clean test Linux

CodaFi added a commit to CodaFi/swift that referenced this pull request Feb 3, 2022
A scoped-down version of swiftlang#39307. Implement extension of bound generic types. The important bit here is in TypeCheckGeneric where we now use the underlying type of a typealias and its associated nominal type decl when we're generating substitutions for the extended type.

Put this behind a new experimental flag

-enable-experimental-bound-generic-extensions

Resolves SR-4875
Resolves rdar://17434633
@Azoy Azoy closed this Feb 3, 2022
@Azoy Azoy deleted the extending-specialized-types-nonsense branch February 3, 2022 17:55
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.

5 participants