Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transform into classes with var fields #401

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ trait ProductTypesPlatform extends ProductTypes { this: DefinitionsPlatform =>
// We have to drop that suffix to align names, so that comparing is possible.
val n: String = getDecodedName(setter)
val name =
if (isVar(setter)) n.substring(0, n.length - "_$eq".length) else n
if (isVar(setter)) n.stripSuffix("_$eq").stripSuffix("_=") else n
name -> setter
}
.filter { case (name, _) => !paramTypes.keySet.exists(areNamesMatching(_, name)) }
Expand Down
11 changes: 11 additions & 0 deletions chimney/src/test/scala/io/scalaland/chimney/IssuesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,15 @@ class IssuesSpec extends ChimneySpec {
Bar("b").transformInto[Foo] ==> Foo("b")
Foo("b").into[Bar2].withFieldConst(_.number, 3).transform ==> Bar2("b", 3)
}

test("fix issue #400") {
import Issue400.*

Foo("b").transformInto[Bar] ==> Bar("b")
Foo("b").into[Bar].transform ==> Bar("b")
Foo("b").transformIntoPartial[Bar].asOption ==> Some(Bar("b"))
Foo("b").intoPartial[Bar].transform.asOption ==> Some(Bar("b"))
Foo("b").into[Bar2].enableDefaultValues.transform ==> Bar2("b", "ok")
Foo("b").intoPartial[Bar2].enableDefaultValues.transform.asOption ==> Some(Bar2("b", "ok"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,9 @@ object Issue297 {
case class Bar(value: String)
case class Bar2(value: String, number: Int)
}

object Issue400 {
case class Foo(value: String)
case class Bar(var value: String)
case class Bar2(var value: String, var value2: String = "ok")
}