scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Recursion limit exceeded on extending enum with higher-kinded and proper type

Open felher opened this issue 9 months ago • 0 comments

Compiler version

3.3.3 LTS and 3.4.1

Minimized code

enum E[F[_], A]:
  case A extends E[Option, Int]
  case B extends E[Function0, Double]
  case C extends E[Function0, String]

Scastie: https://scastie.scala-lang.org/2rs9WkJ9S7Wft85WByTXtw

Output

For case C the compiler says:

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.
For the unprocessed stack trace, compile with -Yno-decode-stacktraces.
A recurring operation is (inner to outer):

  subtype [X0] >: Option[X0] & (() => X0) <: Option[X0] | (() => X0) <:< [R] =>> () => R

Expectation

Should compile (or give a clearer error message)

"Workaround"

Add a variance annotation to F[_]

felher avatar May 03 '24 07:05 felher