title: How to optimize Scala double Call of Recursive Function
body: <p>I'm trying to get this Recursive Function to work:</p>
  
  <pre><code>@tailrec
  def rec(n: BigInt): BigInt = {
    if (n == 0) 0
    else if (n == 1) 1
    else (rec(n - 1) + rec(n - 2))
  }
  </code></pre>
  
  <blockquote>
    <p>Error:(13, 24) could not optimize @tailrec annotated method rec: it contains a recursive call not in tail position
          else (rec(n - 1) + rec(n - 2))</p>
  </blockquote>
  
  <p>How can this be optimized to work with tailrec?</p>