title: Why does this simple Swift generics construct fail to compile?
body: <p>I'm working on my first Swift based project (xcode 6.3.2) and don't seem to get a simple generics construct to build.</p>
  
  <p>The following seems to fail to compile on xcode 6.3.2 (compiler exit with code 1):</p>
  
  <pre><code>// with :AnyObject constraint =&gt; compiler crash
  class GenericsTest : MyDelegate{
  
      static let instance = GenericsTest()
  
      private init(){
          var wrapper = MyWrapper&lt;MyDelegate&gt;(inner: self)
  
          if let md = wrapper.inner {
              println("delegate value \(md.someString)")
          }
      }
  
      // MyDelegate impl
      var someString = "my delegate impl"
  
  }
  
  protocol MyDelegate : class {
      var someString : String {get set}
  }
  
  class MyWrapper&lt;T: AnyObject&gt;{
      private (set) var inner : T?
  
      init(inner : T){
          self.inner = inner
      }
  
  }
  </code></pre>
  
  <p>It looks like the Swift compiler does not like the :AnyObject type constraint of MyWrapper; the following code compiles and runs without any problem:</p>
  
  <pre><code>// no :AnyObject constraint
  class GenericsTest : MyDelegate{
  
      static let instance = GenericsTest()
  
      private init(){
          var wrapper = MyWrapper&lt;MyDelegate&gt;(inner: self)
  
          if let md = wrapper.inner {
              println("delegate value \(md.someString)")
          }
      }
  
      // MyDelegate impl
      var someString = "my delegate impl"
  
  }
  
  protocol MyDelegate : class {
      var someString : String {get set}
  }
  
  class MyWrapper&lt;T&gt;{
      private (set) var inner : T?
  
      init(inner : T){
          self.inner = inner
      }
  
  }
  </code></pre>
  
  <p>I need the :AnyObject type constraint because I'm actually trying to create a weak wrapper, which requires this constraint, like so:</p>
  
  <pre><code>// with weak wrapper and obligatory :AnyObject constraint (compiler crash)
  class GenericsTest : MyDelegate{
  
      static let instance = GenericsTest()
  
      private init(){
          var wrapper = MyWrapper&lt;MyDelegate&gt;(inner: self)
  
          if let md = wrapper.inner {
              println("delegate value : \(md.someString)")
          }
      }
  
      // MyDelegate impl
      var someString = "my delegate impl"
  
  }
  
  protocol MyDelegate : class {
      var someString : String {get set}
  }
  
  class MyWrapper&lt;T: AnyObject&gt;{
      weak private (set) var inner : T?
  
      init(inner : T){
          self.inner = inner
      }
  
  }
  </code></pre>
  
  <p>Anybody any idea how to work around this issue?</p>