title: error: generic parameter 'T' could not be inferred in swift
body: <p>I have function which make flatted array from nested array. It works perfectly for int array.</p>
  
  <pre><code>let array: [Any] = [1, 2, [3]]
  
  func makeFlatArray(_ array: [Any]) -&gt; [Int] {
      var flatArray = [Int]()
      for item in array {
          if let item = item as? Int {
              flatArray.append(item)
          } else if let item = item as? [Any] {
              let result = makeFlatArray(item)
              flatArray += result
          }
      }
      return flatArray
  }
  </code></pre>
  
  <p>But I want make it generic and I have got error when trying.</p>
  
  <pre><code>func makeFlatArrayGeneric&lt;T&gt;(_ array: [Any]) -&gt; [T] {
      var flatArray = [T]()
      for item in array {
          if let item = item as? T {
              flatArray.append(item)
          } else if let item = item as? [Any] {
              let result = makeFlatArrayGeneric(item)
              flatArray += result
          }
      }
      return flatArray
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Playground execution failed:
  
  error: FlatNestedArraysExample.playground:22:26: error: generic parameter 'T' could not be inferred
              let result = makeFlatArrayGeneric(item)
                           ^
  
  FlatNestedArraysExample.playground:16:6: note: in call to function 'makeFlatArrayGeneric'
  func makeFlatArrayGeneric&lt;T&gt;(_ array: [Any]) -&gt; [T] {
  </code></pre>