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

Tailcalls reports less useful error #10435

Closed
som-snytt opened this issue Jul 27, 2017 · 1 comment
Closed

Tailcalls reports less useful error #10435

som-snytt opened this issue Jul 27, 2017 · 1 comment

Comments

@som-snytt
Copy link

As reported on SO:

$ scala
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> import scala.annotation.tailrec
import scala.annotation.tailrec

scala> @tailrec private def loop[V](key: String): V = key match { case _ => loop[V](key) }

scala> @tailrec private def loop[V](key: String): V = key match { case _ => loop(key) }
<console>:12: error: could not optimize @tailrec annotated method loop: it contains a recursive call not in tail position
       @tailrec private def loop[V](key: String): V = key match { case _ => loop(key) }
                                                                                ^

scala> @tailrec private def loop[V](key: String): V = loop(key)
<console>:12: error: could not optimize @tailrec annotated method loop: it is called recursively with different type arguments
       @tailrec private def loop[V](key: String): V = loop(key)
                                                      ^

You'd expect the last error message also for the first message.

With -Ydebug -Ylog:tailcalls:

[log tailcalls] Cannot rewrite recursive call at: source-<console>,line-12,offset=173 because: it is called recursively with different type arguments
[log tailcalls] Cannot rewrite recursive call at: source-<console>,line-12,offset=177 because: it contains a recursive call not in tail position
<console>:12: error: could not optimize @tailrec annotated method loop: it contains a recursive call not in tail position
       @tailrec private def loop[V](key: String): V = key match { case _ => loop(key) }
                                                                                ^

On 2.13, note that with lots of debug output, we lose the source code to scrolling:

[log tailcalls] Cannot rewrite recursive call at: source-<console>,line-1,offset=69 because: it is called recursively with different type arguments
[log tailcalls] Cannot rewrite recursive call at: source-<console>,line-1,offset=73 because: it contains a recursive call not in tail position
                                                                                ^
       error: could not optimize @tailrec annotated method loop: it contains a recursive call not in tail position
@som-snytt
Copy link
Author

presumably scala/scala#6065

@SethTisue SethTisue added this to the 2.12.4 milestone Nov 25, 2020
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

3 participants