title: Default parameter as generic type
body: <p>I have protocol and his implementation written in Swift:</p>
  
  <pre><code>protocol P {
  }
  
  struct A: P {
  }
  </code></pre>
  
  <p>Protocol is used as generic type for some function:</p>
  
  <pre><code>func foo&lt;T: P&gt;(param: T) {
  }
  
  func foo() {
      foo(param: A())
  }
  </code></pre>
  
  <p>Until now everything works properly. But I would like to set A() as a default parameter of given function:</p>
  
  <pre><code>func foo&lt;T: P&gt;(param: T = A()) {
  }
  </code></pre>
  
  <p>Unfortunately with following error:</p>
  
  <blockquote>
    <p>Default argument value of type 'A' cannot be converted to type 'T'.</p>
  </blockquote>
  
  <p>Or</p>
  
  <pre><code>func foo&lt;T: P&gt;(param: T = A() as P) {
  }
  </code></pre>
  
  <p>,</p>
  
  <pre><code>let a: P = A()
  func foo&lt;T: P&gt;(param: T = a) {
  }
  </code></pre>
  
  <p>Returns:</p>
  
  <blockquote>
    <p>Default argument value of type 'P' cannot be converted to type 'T'</p>
  </blockquote>
  
  <p>Or</p>
  
  <pre><code>func foo&lt;T: P&gt;(param: T = A() as T) {
  }
  </code></pre>
  
  <p>Returns:</p>
  
  <blockquote>
    <p>'A' is not convertible to 'T'; did you mean to use 'as!' to force downcast?</p>
  </blockquote>
  
  <p>What I'm doing wrong? Where is the problem?</p>
  
  <p>I do not want to use force cast like this:</p>
  
  <pre><code>func foo&lt;T: P&gt;(param: T = A() as! T) {
  }
  </code></pre>
  
  <p>Thank you in advance.</p>