title: How can I restore type generic type inference in Swift result builders?
body: <p>When designing result builders which consume and product generic types, I often find myself needing to spell out types in an annoyingly explicit way. Consider this toy example:</p>
  <pre class="lang-swift prettyprint-override"><code>@resultBuilder enum SomeBuilder {
      static func buildBlock(_ v: Result&lt;Int,Error&gt;) -&gt; Result&lt;Int,Error&gt; { v }
  }
  struct SomeStruct {
      init(@SomeBuilder _ v: () -&gt; Result&lt;Int,Error&gt;) {}
  }
  
  let x = SomeStruct {
      Result.success(0)
  }
  </code></pre>
  <p><code>SomeBuilder</code> is almost the simplest possible <code>@resultBuilder</code>: it takes in single values of type <code>Result&lt;Int,Error&gt;</code> and returns them as-is. <code>SomeStruct</code> is a simple struct with an initializer that takes a single <code>@SomeBuilder</code> closure which produces <code>Result&lt;Int,Error&gt;</code>. Consequently, it makes sense to me that this code should compile. Swift should be able to figure out that <code>Result.success(0)</code> refers to <code>Result&lt;Int,Error&gt;.success(0)</code> because this is the only type that could make sense in this context. However, this example fails to compile with</p>
  <pre class="lang-plaintext prettyprint-override"><code>_:9:5: error: cannot convert value of type 'Result&lt;Int, _&gt;' to expected argument type 'Result&lt;Int, Error&gt;'
      Result.success(0)
      ^
  _:9:5: note: arguments to generic parameter 'Failure' ('_' and 'Error') are expected to be equal
      Result.success(0)
      ^
  _:9:5: error: generic parameter 'Failure' could not be inferred
      Result.success(0)
      ^
  _:9:5: note: explicitly specify the generic arguments to fix this issue
      Result.success(0)
      ^
            &lt;Int, &lt;#Failure: Error#&gt;&gt;
  </code></pre>
  <p>On the same line, Swift claims that it cannot infer the <code>Failure</code> type of <code>Result.success(0)</code> and then claims that it knows the failure must be <code>Error</code>. I can get this code to compile by using</p>
  <pre class="lang-swift prettyprint-override"><code>let x = SomeStruct {
      Result&lt;Int,Error&gt;.success(0)
  }
  </code></pre>
  <p>but in real examples, being this verbose with the types is extremely inhibitive to the DSLs I want to design.</p>
  <p>Is this a bug in the compiler? How can I get Swift to infer generic types in result builders such as this one?</p>