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
Possible regression in 2.9: @tailrec annotated method rejected by scalac #4649
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4649?orig=1 |
@paulp said: |
@adriaanm said (edited on Jun 11, 2012 12:06:00 PM UTC): |
@VladUreche said: Anyway, bug accepted :) |
not fixed in Scala 3 (3.4.0-RC2) either |
And if you wondered why this ticket is open but has a
|
It is not discriminating in detecting leftover calls:
also complains
as does dotty. So it's about user expectation:
It's not obvious to me what is expected to be obvious, such as the OP example. That is obviously tricky. The dotty style guide says only use the annotation if there is a danger that unintended recursion could blow the stack. The choice is either to warn about any possible recursion (that may introduce stack frames) or only self-recursion (which the optimization could possibly make safe). In other words, only warn about self-recursions because that is what you can do something about. Perhaps an additional lint could tack on other recursive references. (One could imagine a more powerful lint that warns about mutual recursion.) |
The following compiled with Scala 2.8.1:
In 2.9.0 and 2.9.0.1, I get:
To my understanding, the method is tail recursive, as the first occurrence of "lazyFilter" is not a call, but a closure that is passed to cons.
I'm not sure if this only a bug in the evaluation of @tailrec, or if the 2.9 compiler really cannot apply tailrec optimization here anymore. In the latter case, it would affect the Stream class as well.
Could you please clarify about this.
Thanks.
The text was updated successfully, but these errors were encountered: