Closed
Description
In Scala 3, there exists a method fromProduct
that gets automatically generated in case classes' companion objects. For backwards compatibility, this methods needs to be explicitly re-implemented and needs to accept tuples of all the necessary arities.
The generated should look something like this
def fromProduct(p: Product): Person = p.productArity match
case 2 =>
Person(
p.productElement(0).asInstanceOf[...],
p.productElement(1).asInstanceOf[...],
)
case 3 =>
Person(
p.productElement(0).asInstanceOf[...],
p.productElement(1).asInstanceOf[...],
p.productElement(2).asInstanceOf[...],
)
...
Context:
- https://contributors.scala-lang.org/t/can-we-make-adding-a-parameter-with-a-default-value-binary-compatible/6132/29?u=sideeffffect
- Improve the "Backwards compatible case classes" guide with Scala 2 and 3 specifics scala/docs.scala-lang#2788
- Add case classes for Ember client and server configuration http4s/http4s#7066 (comment)
/cc @armanbilge
Metadata
Metadata
Assignees
Labels
No labels