You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is best demonstrated with the following example:
importio.scalaland.chimney.dsl._importio.scalaland.chimney.TransformercaseclassFoo(a: Int, b: Int)
caseclassBar(c: Int=0)
caseclassFooWrapper(foo: Foo)
caseclassBarWrapper(bar: Option[Bar])
// warning below that localT is never usedimplicitvalt:Transformer[FooWrapper, BarWrapper] = {
implicitvallocalT:Transformer[Foo, Bar] = foo =>Bar(foo.a + foo.b)
Transformer.define[FooWrapper, BarWrapper].withFieldRenamed(_.foo, _.baz).buildTransformer
}
// warning: local val localT in value t is never used// implicit val localT: Transformer[Foo, Bar] = foo => Bar(foo.a + foo.b)// ^// error: No warnings can be incurred under -Xfatal-warnings.// no warning because Bar has a default value in its default constructorimplicitvalt:Transformer[FooWrapper, BarWrapper] =Transformer.define[FooWrapper, BarWrapper].withFieldRenamed(_.foo, _.baz).buildTransformer
FooWrapper(Foo(1, 2)).transformInto[BarWrapper]
// BarWrapper(Bar(0))// redefine wrapper transformer with a Transformer[Foo, Bar] outside of a local scopeimplicitvalfooBarT:Transformer[Foo, Bar] = foo =>Bar(foo.a + foo.b)
implicitvalnewT:Transformer[FooWrapper, BarWrapper] =Transformer.define[FooWrapper, BarWrapper].withFieldRenamed(_.foo, _.baz).buildTransformer
FooWrapper(Foo(1, 2)).transformInto[BarWrapper]
// BarWrapper(Bar(3))
There are obvious workarounds. disableDefaultValues can be used when building the wrapper transformer, but this is annoying when defining transformers with code generated by ScalaPB because the unknownFields argument must have a default value specified. Transformers can always be defined outside of a local scope, but sometimes a local scope is desired if multiple transformers require different transformation behavior for a given type in the same package.
The text was updated successfully, but these errors were encountered:
and I didn't feel the need to add a test case for it as there is already one. Once #325 is published if you still find that there is a bug, please reopen.
Chimney version: 0.6.1 (Latest)
This issue is best demonstrated with the following example:
There are obvious workarounds.
disableDefaultValues
can be used when building the wrapper transformer, but this is annoying when defining transformers with code generated by ScalaPB because theunknownFields
argument must have a default value specified. Transformers can always be defined outside of a local scope, but sometimes a local scope is desired if multiple transformers require different transformation behavior for a given type in the same package.The text was updated successfully, but these errors were encountered: