Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No compiling error when code is not tailrec #11612

Open
hepin1989 opened this issue Jul 6, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@hepin1989
Copy link

commented Jul 6, 2019

object Test  extends App {

  println(methodA(1,false))

  @tailrec
  def methodA(input: Int,condition:Boolean): Int = {
    if (condition)
      methodA(input + 2, condition)
    else
      methodB(input + 2, condition)
  }

  @tailrec
  def methodB(input: Int,condition:Boolean): Int = {
    if (condition)
      methodB(input + 3, condition)
    else
      methodA(input + 3, condition)
  }
}

should not compile

@NthPortal

This comment has been minimized.

Copy link

commented Jul 6, 2019

@tailrec only requires that there exists at least one call to itself, and that all calls to itself are in tail position

@som-snytt

This comment has been minimized.

Copy link

commented Jul 6, 2019

That's a good one. Is there something useful to lint, short of analyzing the world? Often the terminating case is something simple like Nil or 0, but maybe that is too simple.

I was going to try something out, but got distracted by other things that made no sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.