-
Notifications
You must be signed in to change notification settings - Fork 22
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
Error during derivation for recursive data types #144
Comments
It looks like it might be a bug. I will try it out later, but in the meantime - we have a test for |
I just tried it and it doesn't work either (the implementation is functionally identical except for some additional cases in my code).
|
Ok, thanks for trying 👍 |
I'm not sure if I ran into into the same issue but I have issues with recursion as well: // THIS WORKS
@Test
def testRec: Unit =
final case class Rec(as: Vector[Rec])
Typeable[Rec]
// THIS DOES NOT WORK
final case class Rec2(as: Vector[Rec2])
@Test
def testRec2: Unit =
Typeable[Rec2] is this expected behavior? The second example is generally how I'd summon the Typeable instance in a different piece of code than the case classes |
@tschuchortdev sorry that I didn't see this sooner, but you need to make the coproduct instances by-name if you want it to work with recursive types. The same applies to our example in the tests: given coproductFunctorK[D[_[_]]] (using cInst: => K11.CoproductInstances[FunctorK, D]): FunctorK[D] with {
extension[F[_]] (df: D[F])
override def mapK[G[_]](fg: [A] => F[A] => G[A]): D[G] =
cInst.fold(df) {
[t[f[_]] <: D[f]] => (caseFunctorK: FunctorK[t], _case: t[F]) =>
caseFunctorK.mapK(_case)(fg)
}
} @@ -333,7 +333,7 @@ object FunctorK:
given [T]: FunctorK[K11.Id[T]] with
def mapK[A[_], B[_]](at: A[T])(f: A ~> B): B[T] = f(at)
- given functorKGen[H[_[_]]](using inst: K11.Instances[FunctorK, H]): FunctorK[H] with
+ given functorKGen[H[_[_]]](using inst: => K11.Instances[FunctorK, H]): FunctorK[H] with
def mapK[A[_], B[_]](ha: H[A])(f: A ~> B): H[B] =
inst.map(ha)([t[_[_]]] => (ft: FunctorK[t], ta: t[A]) => ft.mapK(ta)(f)) |
@agaro1121 that's a different issue. |
I'm trying to generically derive instances of
FunctorK
for recursive data structures:Given following example
an error will be thrown by the compiler:
A similar problem also appears for classes like this:
Note that an almost identical error with
mkProductInstances
can be produced depending on the order of summoning (Foo2
orFoo2Rec
first).I believe the error might occur because of an infinite recursion in the derivation logic that reaches the inlining depth limit. When the inlining limit is reached, further calls to the inline function (
ErasedCoproductInstances.apply
?) are no longer inlined, perhaps causing the types to no longer match. A different error message, which I am unfortunately unable to reproduce, suggested this to me.I understand that recursive data structures were already addressed in #40, so I'm not sure if it's a bug in the library or in my own code.
Library version: 3.3.0
Scala version: 3.2.1
IntelliJ plugin version: 2023.1.548
The text was updated successfully, but these errors were encountered: