Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

UseOptionExistsNotPatMatch should take @tailrec into account #60

Open
seanmcl opened this issue Jun 30, 2017 · 0 comments
Open

UseOptionExistsNotPatMatch should take @tailrec into account #60

seanmcl opened this issue Jun 30, 2017 · 0 comments

Comments

@seanmcl
Copy link

seanmcl commented Jun 30, 2017

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.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant