title: Scala forward reference of nested recursive function
body: <p>I have this really simple method definition with a nested recursive function:</p>
  
  <pre><code>def bar(arr : Array[Int]) : Int = {
    val foo : Int =&gt; Int = (i: Int) =&gt; if(i == 0) 0 else i + foo(i-1)
    foo(3)
  }
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>&lt;console&gt;:36: error: forward reference extends over definition of value foo
       val foo : Int =&gt; Int = (i: Int) =&gt; if(i == 0) 0 else i + foo(i-1)
                                                                ^
  </code></pre>
  
  <p>If I just put the val foo: ... = ... line by itself, and not nested within a def, everything works</p>