[swift-evolution] [Draft] Introducing StaticSelf, an Invariant Self

Nicola Salmoria nicola.salmoria at gmail.com
Fri May 13 04:46:38 CDT 2016


Matthew Johnson via swift-evolution <swift-evolution at ...> writes:

> Consider the following example, under the current system:
> protocol StringCreatable {
>     static func createWithString(s: String) -> Self
> }
> 
> extension NSURL: StringCreatable {
>  // cannot conform because NSURL is non-final
>  // error: method 'createWithString' in non-final class 'NSURL' must
> return `Self` to conform to protocol 'A'
> }Introducing a static, invariant version of Self permits the desired
> conformance:
> protocol StringCreatable {
>     static func createWithString(s: String) -> StaticSelf
> }

I'm not convinced by this example.

I think the problem to solve here is the interaction of protocols with
classes.
A related issue was illustrated by Tony Allevato here
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160502
/016294.html

I think that before attempting to solve this specific problem introducing a
new notation, the general design of the interaction between protocols and
class inheritance should be reviewed.


Nicola



More information about the swift-evolution mailing list