I do not think that I was conflating these two aspects. Using #type(self) would 
return the particular type of the current instance (dynamic type) while using 
#type(A.var) would return the declared (static) type of the property. Now, 

  let a = A()
  #type(a.var) 

would again return the actual (dynamic) type of var

In essence, I don’t see why we need to separate the mechanisms for querying 
these types when the distinction can be made on the grounds whether we are 
querying the type of a particular value/instance or a particular (not 
instantiated) declaration. 

— Taras

P.S. Does Swift today even have the means of querying the static type of a 
variable once it has been instantiated, i.e. can I programmatically  find out 
that  x has been declared as P in this scope:

let x : P = TypeThatConformsToP()

If you really want to differentiate between these two then we’d need two 
separate mechanisms, e.g. #statictype(), #dynamictype(), with #dynamictype() 
referring to the  instantiated value and $statictype() referring to the 
variable declaration.



> On 14 Apr 2016, at 22:59, Joe Groff <[email protected]> wrote:
> 
>> 
>> On Apr 14, 2016, at 1:11 PM, Taras Zakharko <[email protected]> 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

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to