You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As @slavapestov explained to me in the comments, a protocol with a Self requirement in covariant position (i.e. as a method return type) doesn't prohibit the use of the protocol as an existential.
The same should be true for property requirements returning Self, but that is currently (Swift 4.1) not implemented.
So this code fails but shouldn't:
protocolPropertyBuilder {
varbuilder: Self { get }
}
varpropertyBuilders: [PropertyBuilder] = []
// error: protocol 'PropertyBuilder' can only be used as a generic constraint because it has Self or associated type requirements
We allow Self in covariant position. So actually the protocol containing the get-only property should be accepted as an existential type also, however this isn't implemented yet.
Environment
Swift version 4.0.3, Xcode 9.2 (9C40b), macOS 10.13.2 (17C88)
Additional Detail from JIRA
md5: cf582c140c3c743b71f1044e04c0d262
is duplicated by:
Issue Description:
As @slavapestov explained to me in the comments, a protocol with a
Self
requirement in covariant position (i.e. as a method return type) doesn't prohibit the use of the protocol as an existential.Example:
The same should be true for property requirements returning
Self
, but that is currently (Swift 4.1) not implemented.So this code fails but shouldn't:
Notes:
I saw this in Patterns for Working With Associated Types by Benedikt Terhechte (search for "once you use a method instead of a property").
The text was updated successfully, but these errors were encountered: