[swift-evolution] [Pitch] Rename `x.dynamicType` to `x.Self`

Joe Groff jgroff at apple.com
Thu Apr 14 15:59:29 CDT 2016


> On Apr 14, 2016, at 1:11 PM, Taras Zakharko <taras.zakharko at uzh.ch> wrote:
> 
> I do not understand why we can’t do
> 
>  type(self)
> 
> or even
> 
> #type(self)
> 
> Personally, I find .Self business to be quite confusing and idiosyncratic. Having a generic #type() directive would be a general improvement for the language design and it would also open up future possibilities such as
> 
> extension A where A.B == #type(A.C.property1) {
> 
> }
> 
> and other potentially useful things. 

Swift's type system has static and dynamic manifestations, and you're conflating them here. #type in a situation like `where A.B == #type(A.C.property1)` would have to produce the static type of property, whereas `x.dynamicType` today produces the dynamic type of a class or existential.

-Joe


More information about the swift-evolution mailing list