title: Why can't Dart infer the type of List.fold()?
body: <p>I am trying <a href="https://api.dartlang.org/stable/2.1.0/dart-core/Iterable/fold.html" rel="noreferrer"><code>List.fold()</code></a> in Dart 2.1.0:</p>
  
  <pre><code>void main() {
    final a = [1,2,3];
    print(a.fold(0, (x,y) =&gt; x + y));
  }
  </code></pre>
  
  <p>It comes back with an error: </p>
  
  <blockquote>
    <p>Error: The method '+' isn't defined for the class 'dart.core::Object'.</p>
    
    <p>Try correcting the name to the name of an existing method, or defining a method named '+'.</p>
  </blockquote>
  
  <p>Seems that it can't infer the type of <code>x</code> to be <code>int</code>, so doesn't know how to apply the <code>+</code> there.</p>
  
  <p>According to the <a href="https://api.dartlang.org/stable/2.1.0/dart-core/Iterable/fold.html" rel="noreferrer">method spec</a>, <code>x</code> should have the same type as the initial value <code>0</code>, which is obviously an <code>int</code>. <strong>Why can't Dart infer that?</strong></p>
  
  <p>I can make it work by explicitly tipping the type:</p>
  
  <pre><code>void main() {
    final a = [1,2,3];
    print(a.fold&lt;int&gt;(0, (x,y) =&gt; x + y));
  }
  </code></pre>
  
  <p>But I am a little disappointed that Dart cannot infer that for me. Its type inference seems stronger in most other cases.</p>