Transforming between case classes with context bounds #709
-
Hello, We're currently migrating our codebase from 0.7.5 trying to get to latest (1.7.3 at time of writing). There appears to be a change of behaviour when transforming between case classes that have type parameters with context bounds. With the following toy code:
Things work on 0.7.5, but not on 1.7.3 (trying in Scastie it seems to be 0.8.0 when this changed), giving the compile error:
This somewhat makes sense, I can understand the implicit parameters being given names under the hood, which is what the chimney macros see, and similarly the implicit is expected from the source. My question is: what would be a best practice pattern to follow for transforming between case classes with context bounds? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To be honest it was a pure accident that it worked on older versions, I believe we might have used quasiquotes somewhere and they resolved implicits during splicing - making the whole macro code unaware that there was an implicit to handle, and how to proceed when it's missing. It must've disappear while rewriting code to format that could keep behavior consistent between Scala 2.12/2.13/3. I think it's generally an antipattern to use implicits in case classes (or use any case classes with multiple parameters lists - many libraries simply do not support this), but if you already committed to them:
ATM Chimney does not support resolving arbitrary implicits as arguments, someone would have to implement it:
|
Beta Was this translation helpful? Give feedback.
To be honest it was a pure accident that it worked on older versions, I believe we might have used quasiquotes somewhere and they resolved implicits during splicing - making the whole macro code unaware that there was an implicit to handle, and how to proceed when it's missing. It must've disappear while rewriting code to format that could keep behavior consistent between Scala 2.12/2.13/3.
I think it's generally an antipattern to use implicits in case classes (or use any case classes with multiple parameters lists - many libraries simply do not support this), but if you already committed to them:
you can provide custom constructor which would have them applied: