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

@tailrec fails silently on mutual recursion #8767

Open
scabug opened this issue Jul 31, 2014 · 1 comment
Open

@tailrec fails silently on mutual recursion #8767

scabug opened this issue Jul 31, 2014 · 1 comment
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jul 31, 2014

The recursive call to f() below, from inside g(), is not recognized as either happening in tail position or as causing an error, hence producing code consuming an non-constant amount of stack space:

val foo = false; @tailrec def f(): Int = { if (foo) f() else g() }; def g(): Int = f();
@tailrec def f[T](l: List[T]): Int = { val v = l match { case Nil => 0; case a :: l1 => g(l1) }; f[T](Nil)}; def g[T](l1: List[T]): Int = f(l1);

If you wonder why would one care, the original example is in unificationHelper here — I noticed because of a StackOverflowException:

https://github.com/inc-lc/ilc-scala/blob/597a1e6b53dedf9d626061d7b7a9e9da66df499f/src/main/scala/ilc/feature/inference/Inference.scala#L126

In all cases, the code can be made tail-recursive by inlining. However, I imagine this cannot be supported easily. In that case, the code should simply be rejected by the analysis done for tailrec.

@scabug
Copy link
Author

scabug commented Jul 31, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8767?orig=1
Reporter: @Blaisorblade
Affected Versions: 2.11.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants