title: could not optimize @tailrec annotated method loop: it contains a recursive call not in tail position
body: <p>I have the following recursive function which I want to use tail recursion on it. But compiler complains about my implementation with this error:<code>Error:(79, 7) could not optimize @tailrec annotated method loop: it contains a recursive call not in tail position
        n match {
        ^</code></p>
  
  <p>is it because of for loop that it assumes it's  not in tail position?</p>
  
  <pre><code>def dsl[N,E](qNodes:QNodeLike[N,E]*) = {
      val markers = scala.collection.mutable.Map.empty[String, N]
      @tailrec
      def loop(n:QNodeLike[N,E]):Unit = {
        n match {
          case QNode(head, kids:Seq[HalfEdgeLike[E,N]]) =&gt; {
  
            for(kid &lt;- kids){
              kid match {
                case EmptyHalfEdge() =&gt;
                case HalfEdge(e, n) =&gt; loop(n)
              }
            }
          }
  
          case QNodeMarker(head, marker, kids:Seq[HalfEdgeLike[E,N]]) =&gt; {
            markers.update(marker,head)
            for(kid &lt;- kids){
              kid match {
                case EmptyHalfEdge() =&gt;
                case HalfEdge(e, n) =&gt; loop(n)
              }
            }
          }
        }
      }
  
      loop(qNodes.head)
    }
  </code></pre>