Failing to derive from a generic type #460
-
Not sure if this is a feature request, a bug, or a skill issue, so posting here. @ import io.scalaland.chimney.dsl._
@ abstract class A {def x: Int}
@ trait B {def y: String}
@ case class C(x: Int, y: String) extends A with B
@ final case class D(x: Int, y: String, z: Boolean)
@ def cToD(c: C) : D = c.into[D].withFieldConst(_.z, true).transform // works as intended
@ def genericCToD[T <: A with B](genC: T): D = {
genC.into[D].withFieldConst(_.z, false).enableMethodAccessors.transform
}
Chimney can't derive transformation from ammonite.$sess.cmd9.T to ammonite.$sess.cmd7.D
x: scala.Int - no accessor named x in source type ammonite.$sess.cmd9.T
y: java.lang.String - no accessor named y in source type ammonite.$sess.cmd9.T
There are methods in ammonite.$sess.cmd9.T that might be used as accessors for `x`, `y` fields in ammonite.$sess.cmd7.D. Consider using `.enableMethodAccessors`.
genC.into[D].withFieldConst(_.z, false).enableMethodAccessors.transform
^
Compilation Failed
@ abstract class CPrime extends A with B
defined class CPrime
@ def cPrimeToD(cPrime: CPrime): D = {
cPrime.into[D].withFieldConst(_.z, false).enableMethodAccessors.transform
}
< Same bug>
@ def genericCToDNoChimney[T <: A with B](genC: T): D = {
D(genC.x, genC.y, false)} // works
defined function genericCToD
@ val myC = C(1, "ok")
myC: C = C(1, "ok")
@ genericCToDNoChimney(myC)
res12: D = D(1, "ok", false)
@ cToD(myC)
res13: D = D(1, "ok", true) |
Beta Was this translation helpful? Give feedback.
Answered by
michaelbilow
Jan 30, 2024
Replies: 1 comment 1 reply
-
Ah, I found it. I needed |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
michaelbilow
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, I found it. I needed
.enableInheritedAccessors