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
SR-5676 Can't downcast custom generics structs, only arrays
Issue Description:
There appears to be some sort of inconsistency in how subclasses of generic classes are treated with respect to their inheritance.
1. When using a generic class ("model") as a generic parameter for another class ("client"), the specific model is not treated as a a subclass of the generic model:
## Model.swift ##
// Generic model.classValueWrapper<StorageType> {}
// Specific model.classStringValueWrapper: ValueWrapper<String> {}
## Client.swift ##
// Generic client.classAbstractClient<T: ValueWrapper<Any>> {}
// Specific client.classStringClient: AbstractClient<StringValueWrapper> {} // ERROR: 'AbstractClient' requires that 'StringValueWrapper' inherit from 'ValueWrapper<Any>'
2. However, when conforming to a protocol, the specific model is treated as a subclass:
Though this problem can be avoided by avoiding reference types altogether and using a protocol with an associated type, this is not possible in Objective-C.
As a result, it's not possible at all to use this generic client with pre-existing generic models written in Objective-C:
Ok, I can get behind that. It seems then that the only way to use Objective-C generic models in generic Swift clients is to use that 2-parameter interface, correct?
If you want to have parallel hierarchies like this, yes. If you don't actually care about the wrapper type, you can just be generic over the Element on the Swift side and store a value of type ValueWrapper<Element> instead of Wrapper.
Environment
Xcode 11.0
Additional Detail from JIRA
md5: e71dd1d9d60654033c34a9fb81f68e9e
relates to:
Issue Description:
There appears to be some sort of inconsistency in how subclasses of generic classes are treated with respect to their inheritance.
1. When using a generic class ("model") as a generic parameter for another class ("client"), the specific model is not treated as a a subclass of the generic model:
2. However, when conforming to a protocol, the specific model is treated as a subclass:
Though this problem can be avoided by avoiding reference types altogether and using a protocol with an associated type, this is not possible in Objective-C.
As a result, it's not possible at all to use this generic client with pre-existing generic models written in Objective-C:
I'm not sure how much of this is intended behavior or not, but I do believe that this is inconsistent behavior.
The text was updated successfully, but these errors were encountered: