linter icon indicating copy to clipboard operation
linter copied to clipboard

UseOptionExistsNotPatMatch should take @tailrec into account

Open seanmcl opened this issue 7 years ago • 0 comments

Consider

    @tailrec
    private def f(x: Widget, token: Option[String] = None): Boolean = {
      if (foo) true
      else Option(x.getNextToken) match { 
        case None => false
        case Some(tok) => f(x, Some(tok))
      }
    }

When a method is marked @tailrec, the linter should not trigger, since rewriting creates a non-tail-recursive function

 Option(x.getNextToken).exists(t => f(x, Some(t))

This is "morally" tail recursive, but the type checker can't tell. (I didn't look at the bytecode to see if it gets compiled to a tail recursive function.)

seanmcl avatar Jun 30 '17 19:06 seanmcl