Skip to content

Recursion limit exceeded #16061

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

Open
TimWSpence opened this issue Sep 16, 2022 · 2 comments
Open

Recursion limit exceeded #16061

TimWSpence opened this issue Sep 16, 2022 · 2 comments
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc area:typer itype:bug

Comments

@TimWSpence
Copy link
Contributor

Compiler version

3.2.0

Minimized code

import scala.annotation.tailrec

enum Free[+F[_], A]:
  case Return(a: A) extends Free[Nothing, A]
  case Suspend(s: F[A])
  case FlatMap[F[_], X, A](s: Free[F, X], f: X => Free[F, A]) extends Free[F, A]

  def flatMap[F2[x] >: F[x], B](f: A => Free[F2, B]): Free[F2, B] =
    FlatMap(this, f)

  def covary[F2[x] >: F[x]]: Free[F2, A] = this

  @tailrec
  private def step: Free[F, A] = this match
    case FlatMap(Return(a), f) => f(a).step
    case FlatMap(FlatMap(y, f), g) =>
      y.flatMap(a => f(a).flatMap(g)).step
    case x => x

Output

private def step: Free[F, A] = this match
[error]    |                                      ^
[error]    |Recursion limit exceeded.
[error]    |Maybe there is an illegal cyclic reference?
[error]    |If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
[error]    |A recurring operation is (inner to outer):
[error]    |
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  ...
[error]    |
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  traversing for avoiding local references F$3
[error]    |  traversing for avoiding local references F$2
[error]    |  traversing for avoiding local references io.github.timwspence.fpinscala.free.Free[F$2, A]
[error]    |  traversing for avoiding local references (io.github.timwspence.fpinscala.free.Free[F$2, A]#step :
[error]    |  => io.github.timwspence.fpinscala.free.Free[F$2, A]
[error]    |)
[error] one error found
[error] one error found
[error] (coreJVM / Compile / compileIncremental) Compilation failed

Expectation

It should compile or at least fail gracefully. Adding a covary call to step fixes it:

  @tailrec
  private def step: Free[F, A] = this match
    case FlatMap(Return(a), f) => f(a).step
    case FlatMap(FlatMap(y, f), g) =>
      y.flatMap(a => f(a).covary[F].flatMap(g)).step
    case x => x
@TimWSpence TimWSpence added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 16, 2022
@WojciechMazur WojciechMazur added area:typer itype:crash and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 19, 2022
@odersky odersky added area:reporting Error reporting including formatting, implicit suggestions, etc and removed itype:crash labels Sep 26, 2022
@odersky
Copy link
Contributor

odersky commented Sep 26, 2022

It's not a crash. This is a regular error message. Not a very illuminating one, granted, but that's because something fairly complicated is going on.

@dwijnand
Copy link
Member

It's possible this would also been fixed by #15683.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc area:typer itype:bug
Projects
None yet
Development

No branches or pull requests

4 participants