title: Swift protocol with associated type and shadow type erasure
body: <p>I need to pass an object which implements a protocol with associated type into a method, which accepts a protocol. This is not possible in Swift (up to the latest Swift 5) so I use type erasure with a shadow protocol based on <a href="https://medium.com/dunnhumby-data-science-engineering/swift-associated-type-design-patterns-6c56c5b0a73a" rel="nofollow noreferrer">this blog</a>.</p>
  
  <pre><code>protocol ShadowA {
      func test(data: Any) -&gt; String
  }
  
  extension ShadowA {
      func test(data: Any) -&gt; String {
          return "shadow"
      }
  }
  
  protocol A: ShadowA {
      associatedtype AT
  
      func test(data: AT) -&gt; String
  }
  
  class SpecificA: A {
      typealias AT = Int
  
      func test(data: Int) -&gt; String {
          return "specific"
      }
  }
  </code></pre>
  
  <p>Problem is that when I pass the object into the method then the "shadow's default implementation" is called instead of the "generic" one's. You can check the <a href="https://iswift.org/playground?8nt0eG&amp;v=4" rel="nofollow noreferrer">playground</a> to see what is happening.</p>
  
  <p>Is there something wrong or this use case is not possible in Swift at all?</p>