title: Understanding "Use of undeclared type" in inherited generic class
body: <p>I just came across this curious cookie and can't figure out if I'm more surprised by the fact that this doesn't work as expected or that this the first time I'm seeing this in the past five years using Swift every day.</p>
  
  <p>Now, I expected <code>Bar</code> type to be accessible from <code>Baz</code>, but it isn't:</p>
  
  <pre><code>class Foo&lt;Bar&gt; {
      func bar() -&gt; Bar? { nil }
  }
  class Baz: Foo&lt;String&gt; {
      override func bar() -&gt; Bar? { nil } //  Use of undeclared type 'Bar'…
  }
  </code></pre>
  
  <p>It's easily solved with <code>typealias</code>:</p>
  
  <pre><code>class Foo&lt;Bar&gt; {
      typealias Bar = Bar // This just feels so wrong…
      func bar() -&gt; Bar? { nil }
  }
  class Baz: Foo&lt;String&gt; {
      override func bar() -&gt; Bar? { nil } //  That's it…
  }
  </code></pre>
  
  <p><strong>My questions is:</strong> is this mentioned or explained anywhere in the official docs? What's the benefit of hiding <code>Bar</code> from inheriting classes?</p>
  
  <p>One of the reasons this is a rare case is probably because we often pass down the generic type:</p>
  
  <pre><code>class Foo&lt;Bar&gt; {
      func bar() -&gt; Bar? { nil }
  }
  class Baz&lt;Bar&gt;: Foo&lt;Bar&gt; {
      override func bar() -&gt; Bar? { nil } //  No problems…
  }
  </code></pre>
  
  <p>And use protocols with <code>associatedtype</code>, which does the same job as <code>typealias</code> above:</p>
  
  <pre><code>protocol P {
      associatedtype Bar
  }
  class Foo&lt;Bar&gt;: P {
      func bar() -&gt; Bar? { nil }
  }
  class Baz: Foo&lt;String&gt; {
      override func bar() -&gt; Bar? { nil } //  All good…
  }
  </code></pre>
  
  <p>P.S. <strong>I'm not asking how to fix this.</strong> I want to know if the current behaviour is mentioned anywhere in the official documentation or, otherwise, if there's a credible article explaining the reasons why this works the way it does.</p>