linter
linter copied to clipboard
UseOptionExistsNotPatMatch should take @tailrec into account
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.)