Related to an earlier question I asked, I'm trying to validate pairs of types, Models + Presenters. I don't understand why when I implement an associatedtype with a protocol, run time type checking stops working, but only when the types are used inside of a generic function. Sample below:
As a more general thing: If you see unexpected behavior (and you're not sure if the behavior is correct or a bug), filing a bug report on bugs.swift.org would be one option you could take. It may not be a bug but maybe there's something we can do in terms of diagnostics.
For this specific one, I believe the reasoning has to do with the potentially unexpected behavior of type(of:) in generic contexts, which is explained in the "Finding the Dynamic Type in a Generic Context" section of the documentation.
Normally, you don’t need to be aware of the difference between concrete and existential metatypes, but calling type(of:) can yield unexpected results in a generic context with a type parameter bound to a protocol. In a case like this, where a generic parameter T is bound to a protocol P , the type parameter is not statically known to be a protocol type in the body of the generic function. As a result, type(of:) can only produce the concrete metatype P.Protocol .