You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been playing around with the generic typealias which hides the `T.Type` structure and found a strange behavior of `Any.Type`:
public typealias Metatype<T> = T.Type
// true - NO WARNING?
Any.self is Any.Type
// true - Warning: `is` test is always true
Any.self is Metatype<Any>
// true - Warning: `is` test is always true
Int.self is Any.Type
// true - Warning: `is` test is always true
Int.self is Int.Type
// FALSE - should be TRUE - Warning: Cast from `Int.Type` to unrelated type 'Any.Protocol' (aka 'protocol<>.Protocol') always fails
Int.self is Metatype<Any>
// true - Warning: `is` test is always true
Int.self is Metatype<Int>
// works just fine
let anyMetatype: Any.Type = Int.self
// Error: Cannot convert value of type `Int.Type` to specified type `Any.Protocol` (aka 'protocol<>.Protocol')
let anyMetatype: Metatype<Any> = Int.self
// Workaround: store the metatype inside `Any`
let hiddenMetatype: Any = Int.self
// NOT nil
hiddenMetatype as? Any.Type
// NOT nil
hiddenMetatype as? Int.Type
// NIL - should be NOT nil
hiddenMetatype as? Metatype<Any>
// NOT nil
hiddenMetatype as? Metatype<Int>
Update: The issue is caused by this behavior.
Any.self // should be of type `Any.Type`
// BUT
Any.Type // means it can store any metatype, not just the metatype for `Any`
There is no way to express the correct type to store only the metatype for `Any`.
Suggestion:
Introduce standalone `AnyMetatype`
Fix `Any.Type` to be the storage type for the metatype of `Any`
2. Update:
In general this is caused by protocol metatypes becoming `.Protocol` instead of `.Type`.
Environment
Xcode 8 beta 2 (8S162m), Xcode 8 Beta 1
Additional Detail from JIRA
md5: 7a4f140e25b0b4534c2a5644eccee08d
Issue Description:
I've been playing around with the generic typealias which hides the `T.Type` structure and found a strange behavior of `Any.Type`:
Update: The issue is caused by this behavior.
There is no way to express the correct type to store only the metatype for `Any`.
Suggestion:
Introduce standalone `AnyMetatype`
Fix `Any.Type` to be the storage type for the metatype of `Any`
2. Update:
In general this is caused by protocol metatypes becoming `.Protocol` instead of `.Type`.
This issue is part of SE-0126.
The text was updated successfully, but these errors were encountered: