Skip to content

@tailrec not properly enforced #5397

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

Closed
allanrenucci opened this issue Nov 6, 2018 · 2 comments
Closed

@tailrec not properly enforced #5397

allanrenucci opened this issue Nov 6, 2018 · 2 comments

Comments

@allanrenucci
Copy link
Contributor

class Test {
  def cond: Boolean = ???
  def foo(x: => Int) = ???

  @annotation.tailrec
  final def bar: Int =
    if (cond) foo(bar) // should be an error
    else bar
}

t4649 is a pending test case

@odersky
Copy link
Contributor

odersky commented Nov 6, 2018

What is tail recursion? I'd argue this is not a violation of it. What we have is really analogous to

class Test {
  def cond: Boolean = ???
  def foo(x: Test) = x.bar

  @annotation.tailrec
  final def bar: Int =
    if (cond) foo(this) 
    else bar
}

and that one is regarded as tailrecursive as well.

@odersky odersky closed this as completed Nov 6, 2018
@allanrenucci
Copy link
Contributor Author

We decided to report @tailrec failure within local methods as well.

It should cover this example, since by-name expends to closures which expends to local methods

@allanrenucci allanrenucci reopened this Nov 12, 2018
@allanrenucci allanrenucci self-assigned this Nov 12, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 12, 2018
If a method is annotated with @tailrec we now report invalid recursive
call within local method. This means we now visit by-name arguments,
closures and lifted `try`s
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 13, 2018
If a method is annotated with @tailrec we now report invalid recursive
call within local method. This means we now visit by-name arguments,
closures and lifted `try`s
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 13, 2018
If a method is annotated with @tailrec we now report invalid recursive
call within local method. This means we now visit by-name arguments,
closures and lifted `try`s
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 13, 2018
If a method is annotated with @tailrec we now report invalid recursive
call within local method. This means we now visit by-name arguments,
closures and lifted `try`s
allanrenucci added a commit that referenced this issue Nov 14, 2018
Fix #5397: Visit local method in Tailrec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants