-
Notifications
You must be signed in to change notification settings - Fork 22
Scala 2: Recursive type info is not supported: fail-fast with a comprehensive message instead #280
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
Scala 2: Recursive type info is not supported: fail-fast with a comprehensive message instead #280
Conversation
…ehensive message instead
Hi @arnaud-daroussin , Thanks for PR. I remember that recursive types are unfortunately not supported by this library. Do you see any possibility to support it in future? |
It seems very hard, almost impossible. It was possible to hack something in If we wants to handle recursivity in Similar problems occur also on So I think it's possible, but is it worth it? |
And for Scala 3, I have no clue how to fix the compilation error:
|
What you described sounds like memorization and dynamic programming. https://stackoverflow.com/a/6185005/6176274 I met people who wanted this library to support recursive types. I think they wanted to parse JSON data which can have recursive nested documents inside. Yes, it would be nice to solve this problem in another issue. Perhaps you could register new issue and approximately describe its complexity and how it could be solved at least theoretically? |
I guess it would be a question at Scala Users Forum https://users.scala-lang.org/, where Scala Center folks could help to understand Scala 3 Mirror API. It is something really advanced. |
Hi @novakov-alexey,
Here is a small PR to improve the error message when trying to create a type information on a recursive type. We encountered this case and thought the error could be easily detected and fail-fast with a comprehensive message instead of a stack overflow error like this:
When I tried to reproduce the stack overflow error here, I saw this commented test in
SerializerTest
:I thought recursive type derivation could be fixed. I managed to hack
LowPrioImplicits.join()
to work with recursive type butCaseClassSerializer
doesn't support recursivity at every place it computes things iterating over its fields, at least:TupleSerializerBase.getLength()
isImmutableType
copy()
isImmutableSerializer
CaseClassSerializer.duplicate()
CaseClassTypeInfo.createSerializer()
It's a dead end, so the fail-fast solution seems the way to go. Here is the resulting message instead of the stack overflow error:
Interestingly, Scala 3 detects the recursive type derivation problem at compile time, so this PR applies for Scala 2 only.