title: Swift Protocol Extension with AssociatedType Constrained to Collection, Can't Use Subscript
body: <p>I'm trying to write a protocol that conforms to the Collection Protocol, and it has an associatedType - Object and a property object. </p>
  
  <pre><code>protocol DDCDataSource: Collection
  {
      associatedtype Object
      var object: Object {get set}
  }
  </code></pre>
  
  <p>I want to add some default functionality for the case where Object also conforms to the Collection protocol, namely just directly return Object's implementation of these required Collection properties and functions. It seems like it all works except for Collection's requirement for a subscript.</p>
  
  <blockquote>
    <p>Cannot subscript a value of type 'Self.Object' with an index of type 'Self.Object.Index'</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/E6yzf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E6yzf.png" alt="enter image description here"></a></p>
  
  <pre><code>extension DDCDataSource where Object: Collection
  {
      typealias Index = Object.Index
  
      var startIndex: Object.Index {
          get {
              return object.startIndex
          }
      }
  
      var endIndex: Object.Index {
          get {
              return object.endIndex
          }
      }
  
      subscript(position: Object.Index) -&gt; Element
      {
          return object[position]
      }
  
      func index(after i: Object.Index) -&gt; Object.Index {
          return object.index(after: i)
      }
  }
  </code></pre>