Transforming to value class from non-value class no longer works (and vice-versa)
dvgica opened this issue · comments
Checklist
- I read the documentation at https://scalalandio.github.io/chimney/ and checked that the functionality exists
- I verified that the behavior for my use case doesn't match the documentation
- I checked the https://github.com/scalalandio/chimney/issues and haven't found the issue reported
- I confirmed that the bug is not related to functionality that was deprecated: lifted transformers (
TransformerF
s) orunsafeOption
flags
Describe the bug
Transforming from a value class to a non-value class, or vice versa, when the transformation should be automatically derived, previously worked out of the box. In 0.7.3 (and 0.7.2) it does not any longer.
Reproduction
Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 11.0.18).
Type in expressions for evaluation. Or try :help.
scala> import io.scalaland.chimney.dsl._
import io.scalaland.chimney.dsl._
scala> case class Foo(value: String) extends AnyVal
class Foo
scala> case class Bar(value: String)
class Bar
scala> Foo("f").transformInto[Bar]
^
error: Chimney can't derive transformation from Foo to Bar
Bar
value: java.lang.String - no accessor named value in source type java.lang.String
Consult https://scalalandio.github.io/chimney for usage examples.
scala> Bar("b").transformInto[Foo]
^
error: Chimney can't derive transformation from Bar to Foo
java.lang.String
derivation from bar: Bar to java.lang.String is not supported in Chimney!
Consult https://scalalandio.github.io/chimney for usage examples.
Expected behavior
Chimney should be able to automatically derive the transformation.
Actual behavior
See compiler errors above.
Which Chimney version do you use
0.7.3
Which platform do you use
- JVM
- Scala.js
- Scala Native
If you checked JVM
java --version
openjdk 11.0.18 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)
Additional context
This previously worked in 0.6.x, I'm upgrading an existing codebase.
Also, kudos on the 0.7 improvements. Love the new PartialTransformer
API.
Update: this worked in 0.7.1, so I suspect that #265 changed something?
Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 11.0.18).
Type in expressions for evaluation. Or try :help.
scala> import io.scalaland.chimney.dsl._
import io.scalaland.chimney.dsl._
scala> case class Foo(value: String) extends AnyVal
class Foo
scala> case class Bar(value: String)
class Bar
scala> Foo("f").transformInto[Bar]
val res0: Bar = Bar(f)
scala> Bar("b").transformInto[Foo]
val res1: Foo = Foo(b)
Released in 0.7.4.
Awesome, thanks for the quick fix, 0.7.4 looks good!