title: Protocol reference in swift is throwing segmentation fault 11
body: <p>I'm trying to create a Date and Calendar implementation in Swift making heavy use of protocol, but it started throwing segmentation fault 11 in every approach. My current one is this:</p>
  
  <pre><code>protocol CalendarUnit {
    typealias C: Calendar
    init(_ date: Date&lt;C&gt;)
  }
  
  protocol Calendar {
    typealias Second: CalendarUnit
  }
  
  struct GregorianCalendar: Calendar {
  
    struct Second: CalendarUnit {
    }
  }
  
  struct Date&lt;C: Calendar&gt; {
    let timestamp: Int
  
    var second: C.Second { return C.Second(self) }
  }
  </code></pre>
  
  <p>A suspicion is because of the recursion of both protocols bu not sure how to implement this section in another way. Any help is appreciated, thanks in advance</p>
  
  <p>EDIT</p>
  
  <p>Could also use type constriction between the initializer of calendarunit, and the calendar to which it belongs.</p>
  
  <pre><code>protocol CalendarUnit {
    init&lt;C&gt;(date: Date&lt;C&gt;)
  }
  
  protocol Calendar {
  
    typealias Year: CalendarUnit
  }
  
  struct GregorianCalendar: Calendar {
  
    struct Year: CalendarUnit {
  
      init&lt;C&gt;(date: Date&lt;C&gt;) {
      }
    }
  }
  
  struct JulianCalendar: Calendar {
  
    struct Year: CalendarUnit {
  
      init&lt;GregorianCalendar&gt;(date: Date&lt;GregorianCalendar&gt;) {
      }
    }
  }
  
  struct Date&lt;C: Calendar&gt; {
  }
  </code></pre>
  
  <p>In the example I can insert any calendar (julian inside a gregorian) and will satisfy the protocol need but it does not guarantee it's the same calendar. Is there a way to enforce this restriction, preferably without having to repeat the name of the calendar in the typealias?.</p>