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

Give a more specific error when @scala.annotation.tailrec is used on a method that doesn't recurse #3275

Closed
scabug opened this issue Apr 9, 2010 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Apr 9, 2010

Compiling with 2.8.0.Beta1, if I use @scala.annotation.tailrec on a function that doesn't recurse, the compiler simply tells me that it cannot optimise it. It would be very useful if the compiler were able to tell me that this is because the function doesn't recurse.

The use case may sound silly - why annotate the function if it's not recursive? - but it has happened to me a few times where I have refactored a recursive function to no longer recurse, and then scratched my head for a while after getting the compile error.

@scabug
Copy link
Author

scabug commented Apr 9, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3275?orig=1
Reporter: Graham Lea (grlea)

@scabug
Copy link
Author

scabug commented Apr 12, 2010

@paulp said:
I now have fancy detailed @tailrec messages implemented, but I'm putting the patch on ice until after this upcoming release-thing is rolled.

@scabug
Copy link
Author

scabug commented Apr 15, 2010

@paulp said:
(In r21599) Improved @tailrec error messages to specify the reason.
In the process fixed old bug involving tail call transformation.
Closes #3275, #2018. Review by dragos.

@scabug
Copy link
Author

scabug commented Mar 7, 2012

Dan Rosen (mergeconflict) said:
Reopening: when @tailrec is used on a non-recursive method, the default error message is still used: "it contains a recursive call not in tail position".

From TailCalls.scala:

else if (!isRecursiveCall) {
  if (receiverIsSuper) failHere("it contains a recursive call targetting a supertype")
  else failHere(defaultReason)
}

I haven't done any scalac hacking, but I assume this is the spot where you'd want to say "method is non-recursive."

@scabug
Copy link
Author

scabug commented Mar 11, 2012

@paulp said:
79e937bea2

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