-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Describe the bug
I have a method for manipulating objcProtocol that looks like this
func classConforming<P>(to objcProtocol: P.Type) -> P? {
let p: Any = objcProtocol
guard let pp = p as? Protocol else {
return nil
}
return self.objonly_classConformingToProtocol(pp) as? P
}
self.objonly_classConformingToProtocol accepts a Protocol object as parameter and return AnyObject
When I call it like:
classConforming(to: aProtocol.Type.self)
Xcode shows me that aProtocol.Type.self is aProtocol.Type.Protocol and lldb tells me that objcProtocol is "@thick aProtocol.Type.Protocol" and p is "" but print will tell me it is aProtocol.Type and I can't cast it to Protocol, pp will always nil.
I also tried adding where P.Type == Protocol, but the compiler would give me an error:
Generic signature requires types 'P.Type' and 'Protocol' to be the same
I'm not sure how the compiler converts, but I think since Swift lacks a mechanism to determine whether it's a protocol/class/struct/enum/actor, it should at least ensure type consistency when passing parameters