I thought proposal 0309 was accepted a while ago, but I am still getting the old "Protocol can only be used as a generic constraint because it has Self or associated type requirements" error when I try to use a simple protocol with associated types as a variable.
protocol P {
associatedtype A
}
struct X {
var p:P ///Protocol 'P' can only be used as a generic constraint because it has Self or associated type requirements
}
It's too late to bring it into 5.5, as the proposal was only accepted a few weeks before WWDC and the cut off to bring features into 5.5 was passed the month before. Once we merge the implementation, the feature should be available in the next major release (5.6 I presume, likely early next year).
In theory it could be, though the criteria for including changes into a release after the cut-off gets stricter as release get nearer, so as to not destabilize the release, and as a result after the cut-off only low-risk changes or critical bug fixes gets accepted, at least in my experience. The release manager has the final say into what goes into 5.5, so if they decide SE-0309 isn't a high-risk change then we can certainly get it into 5.5. In my opinion, it is better to let it settle in the main branch for a while, as it gives us more time to fix any issues that might arise due to it.
I was hoping to refactor my packages to use this at the same time I refactored them to add the new concurrency stuff.
If the release manager is reading this, please consider adding this to 5.5! I have several projects which have a metric ton of extra boilerplate (or which just can't use PATs) because this is missing. I am guessing I am not the only one...
Yep. The part that landed recently enables only the use of all protocols as types. I am currently working on the second part – which comprises known associated types and covariant erasure for associated types – here. The final part would be to allow targeting a certain property/subscript accessor when only some of the accessors are available.
I am testing "swift-DEVELOPMENT-SNAPSHOT-2021-10-05-a" to see how this feature works.
Here is my test code.
struct Apple {
let count: Int
}
protocol Store {
associatedtype Item
var item: Item { get set }
}
protocol AppleStore: Store where Self.Item == Apple { }
class MySevice {
private var store: AppleStore!
func doStuff() {
let asd = store.item
}
}
Good: Now the declaration of a property with AppleStore type works, unlike in any previous release versions of Swift. This got me super hyped, because this is a very highly anticipated feature for our team (in fact, any teams I have ever worked with).
Bad: Referencing any property or function of an AppleStore instance (for example: let asd = store.item) gives an error, for example: Member 'item' cannot be used on value of protocol type 'AppleStore'; use a generic constraint instead
Are you developing a feature for Swift that makes accessing functions and properties of an AppleStore instance possible? Is there a proposal or PR we can take a look?
Are you developing a feature for Swift that makes accessing functions and properties of an AppleStore instance possible? Is there a proposal or PR we can take a look?
All these features were proposed in SE-309 (some of them are just not implemented yet). There is also a link to the PR I am currently working on in my previous reply.
I am waiting for some final comments on a secondary PR that I want to upstream before we resume work on the main one. I know this has been dragging on for quite a while now, but there seems to be little I can do to ginger up the review feedback routine.
Hello @anthonylatsis !
I was following the github PRs of this SE0309. I am super hyped to see things are merged.
Thank you for the efforts, highly appreciated!
Are there any more PRs regarding this feature? Do you happen to have an idea which Swift version will this be released with?
There's one more upcoming PR for the features described in the proposal, but we're not expecting the progress there to defer the inclusion of already implemented parts in the next release (the plan is to check it off the list in time for the next release anyways).