2016-07-15 17:21 GMT+03:00 Adrian Zubarev via swift-evolution < [email protected]>:
> > - > > If it’s possible to drop T.Metatype, sure why not to make it > Metatype<T>, but I have no idea hod the core team will build this. We > should consider typealias Metatype<T> = T.Metatype as an alternative > implementation, but tackle for Metatype<T>. > > Nice! > > - > > Can you provide a full example? > > let type = Type<Base>(casting: Derived) > > // `type` is the same as this, where we know that `Derived` can be `Base`: > let derived = Type<Derived>() > let base = unsafeBitCast(derived, to: Type<Base>) > > The global dictionary contains only the dynamicTypes which were > instantiated through Type<T>.sharedInstance or dynamicType(someInstance) > function. > > let derived: Any = Derived() > let type = dynamicType(derived) // Type<Any> > > // I'll refer to current syntax here > type.metatype is Derived.Type // true > type.metatype is Base.Type // true > > Here you are, full example: let x = Type<Derived>() // Type<Derived> is not a subtype of Type<Base>, we must construct a new instance of Type<Base> let y = Type<Base>(casting: x)! y === x //=> false // Type<T> are reference types. z will point to the same instance as y let z = unsafeBitCast(y, to: Type<Derived>()) z === y //=> true z === x //=> false // Static and dynamic types are equal here, so we decide to draw from global dictionary let w = Type<Derived>(casting: y)! w === x //=> true w === y //=> false w === z //=> false > I just realized what causes the SR–2085 bug I mentioned earlier. > > > - Any.Type is not the metatype of Any > - Any.Type means that this ‘thing’ can store any metatype > - There is no type that expresses metatype for Any > - We still can get the metatype for Any through Any.self > > I updated SR–2085 and suggested that we need AnyMetatype. > Why? I would prefer to be consistent and make Metatype<Any> the metatype of Any (excuse the pun). And *because* all types are subtypes of Any, instances of Metatype<Any> will still cover all types.
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
