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
Labels

Comments

@scabug
Copy link

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug scabug commented Apr 9, 2010

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

@scabug

This comment has been minimized.

Copy link
Author

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 11, 2012

@paulp said:
79e937bea2

@scabug scabug closed this Mar 11, 2012
@scabug scabug added the enhancement label Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.