<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">I have no problem with the syntax proposed in SE-0068.<br>The rationale briefly mentions that dynamic <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Self</code> will be used anywhere inside the class body. I think that the possibilities that open with this decision should be mentioned in the proposal.</p>
<p style="margin:0px 0px 1.2em!important">We can say that non-final classes, apart from that they can also have instances of themselves, behave very much like protocol existentials. They couple requirements and “default implementation”. Like existential protocols, they can’t have associated types. SE-0068 expands abilities of classes and allows their requirements to contain <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Self</code>. “Default” implementation is mandatory, as usual. Example of code that will be possible:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">// Compiles now
protocol P {
init()
func foo(_ x: Self) -> Self
}
extension P {
func foo(_ x: Self) -> Self {
print(Self.self)
return Self.init()
}
}
struct S : P { }
let x = S()
_ = x.foo(x) // prints "S"
// Will compile after implementation of SE-0068
class A {
required init() {
}
func foo(_ x: Self) -> Self {
print(Self.self)
return Self.init()
}
}
class B : A { }
let y = B()
_ = y.foo(y) // prints "B"
</code></pre><p style="margin:0px 0px 1.2em!important">I find that consistent enough. The annoyance is that we don’t and won’t have the ability to implement protocol requirements with <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Self</code> in classes without <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Self</code>. This is an error:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">protocol P {
func foo() -> Self
}
class A {
func foo() -> A { ... }
}
class B : A {
override func foo() -> B { ... }
}
</code></pre><p style="margin:0px 0px 1.2em!important">The fact that we can’t get rid of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Self</code> in implementation is an abstraction leak.</p>
<p style="margin:0px 0px 1.2em!important">As a side note, seeing <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Self.self</code>, I really look forward to refactoring <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Self</code>, <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">self</code>, <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Type</code>, <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Protocol</code> and <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">MemoryLayout</code>.</p>
<div title="MDH:PGRpdj5JIGhhdmUgbm8gcHJvYmxlbSB3aXRoIHRoZSBzeW50YXggcHJvcG9zZWQgaW4gU0UtMDA2
OC48L2Rpdj48ZGl2PlRoZSByYXRpb25hbGUgYnJpZWZseSBtZW50aW9ucyB0aGF0IGR5bmFtaWMg
YFNlbGZgIHdpbGwgYmUgdXNlZCBhbnl3aGVyZSBpbnNpZGUgdGhlIGNsYXNzIGJvZHkuIEkgdGhp
bmsgdGhhdCB0aGUgcG9zc2liaWxpdGllcyB0aGF0IG9wZW4gd2l0aCB0aGlzIGRlY2lzaW9uIHNo
b3VsZCBiZSBtZW50aW9uZWQgaW4gdGhlIHByb3Bvc2FsLjwvZGl2PjxkaXY+PGJyPjwvZGl2Pjxk
aXY+V2UgY2FuIHNheSB0aGF0IG5vbi1maW5hbCBjbGFzc2VzLCBhcGFydCBmcm9tIHRoYXQgdGhl
eSBjYW4gYWxzbyBoYXZlIGluc3RhbmNlcyBvZiB0aGVtc2VsdmVzLCBiZWhhdmUgdmVyeSBtdWNo
IGxpa2UgcHJvdG9jb2wgZXhpc3RlbnRpYWxzLiBUaGV5IGNvdXBsZSBy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