Skip to content

pat-mat - Recursion limit exceeded in sub-type matching #9782

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

Closed
Sciss opened this issue Sep 13, 2020 · 2 comments · Fixed by #9789
Closed

pat-mat - Recursion limit exceeded in sub-type matching #9782

Sciss opened this issue Sep 13, 2020 · 2 comments · Fixed by #9789

Comments

@Sciss
Copy link
Contributor

Sciss commented Sep 13, 2020

Minimized code

trait Txn[T <: Txn[T]]

trait Elem[T <: Txn[T]]

trait Obj[T <: Txn[T]] extends Elem[T]

trait Copy[In <: Txn[In], Out <: Txn[Out]] {
  def copyImpl[Repr[~ <: Txn[~]] <: Elem[~]](in: Repr[In]): Repr[Out]
  
  def apply[Repr[~ <: Txn[~]] <: Elem[~]](in: Repr[In]): Repr[Out] = {
    val out = copyImpl[Repr](in)
    (in, out) match {
      case (inObj: Obj[In], outObj: Obj[Out]) =>     // problem here
        println("copy the attributes")
      case _ =>
    }
    out
  }
}

Output

https://scastie.scala-lang.org/hzmyXFSrRoq4Na9ZMsIkTQ

Recursion limit exceeded.
Maybe there is an illegal cyclic reference?
If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
A recurring operation is (inner to outer):

  subtype de.sciss.lucre.experiment.Txn[
  LazyRef(
    de.sciss.lucre.experiment.Txn[
      LazyRef(
        de.sciss.lucre.experiment.Txn[
          LazyRef(
            de.sciss.lucre.experiment.Txn[
              LazyRef(
                de.sciss.lucre.experiment.Txn[
                  LazyRef(
                    de.sciss.lucre.experiment.Txn[
                      LazyRef(
                        de.sciss.lucre.experiment.Txn[
                          LazyRef(
                            de.sciss.lucre.experiment.Txn[
                              LazyRef(
                                de.sciss.lucre.experiment.Txn[
                                  LazyRef(
                                    de.sciss.lucre.experiment.Txn[
                                      LazyRef(
                                        de.sciss.lucre.experiment.Txn[
                                          LazyRef(...)
                                        ]
                                      )
                                    ]
                                  )
                                ]
                              )
                            ]
                          )
                        ]
                      )
                    ]
                  )
                ]
              )
            ]
          )
        ]
      )
    ]
  )
] <:< de.sciss.lucre.experiment.Txn[LazyRef(T)]
  subtype LazyRef(T) <:< LazyRef(
  de.sciss.lucre.experiment.Txn[
    LazyRef(
      de.sciss.lucre.experiment.Txn[
        LazyRef(
          de.sciss.lucre.experiment.Txn[
            LazyRef(
              de.sciss.lucre.experiment.Txn[
                LazyRef(
                  de.sciss.lucre.experiment.Txn[
                    LazyRef(
                      de.sciss.lucre.experiment.Txn[
                        LazyRef(
                          de.sciss.lucre.experiment.Txn[
                            LazyRef(
                              de.sciss.lucre.experiment.Txn[
                                LazyRef(
                                  de.sciss.lucre.experiment.Txn[
                                    LazyRef(
                                      de.sciss.lucre.experiment.Txn[
                                        LazyRef(
                                          de.sciss.lucre.experiment.Txn[
                                            LazyRef(...)
                                          ]
                                        )
                                      ]
                                    )
                                  ]
                                )
                              ]
                            )
                          ]
                        )
                      ]
                    )
                  ]
                )
              ]
            )
          ]
        )
      ]
    )
  ]
)
  subtype LazyRef(T) <:< LazyRef(
  de.sciss.lucre.experiment.Txn[
...

Expectation

should compile ( https://scastie.scala-lang.org/UL2Je3yATT6MukbzvP0qRA )

@smarter

This comment has been minimized.

@Sciss
Copy link
Contributor Author

Sciss commented Sep 13, 2020

Same happens when I replace pat-mat with if (in.isInstanceOf[Obj[In]] && out.isInstanceOf[Obj[Out]]) ; if I put place-holders like in.isInstanceOf[Obj[_]] and cast afterwards, it compiles. So doesn't actually require pattern matching.

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

Successfully merging a pull request may close this issue.

4 participants