chimney icon indicating copy to clipboard operation
chimney copied to clipboard

Silent invalid behavior of `withFieldConst` when field name starts with "set"

Open Tvaroh opened this issue 5 months ago • 5 comments

Reproducing example:

object ChimneyBug extends App {

  import io.scalaland.chimney.dsl.*
  import java.util.UUID

  case class From(x: String)
  case class To(uuid: UUID, setUuid: UUID, x: String)

  val result: To =
    From("meh").into[To]
      .withFieldConst(_.uuid, UUID.randomUUID())
      .withFieldConst(_.setUuid, UUID.randomUUID())
      .transform

  println(result)

}

Result:

To(96720c38-267d-4559-855a-02cee6cc8443,96720c38-267d-4559-855a-02cee6cc8443,meh)

If renamed to e.g. settUuid:

object ChimneyBug extends App {

  import io.scalaland.chimney.dsl.*
  import java.util.UUID

  case class From(x: String)
  case class To(uuid: UUID, settUuid: UUID, x: String)

  val result: To =
    From("meh").into[To]
      .withFieldConst(_.uuid, UUID.randomUUID())
      .withFieldConst(_.settUuid, UUID.randomUUID())
      .transform

  println(result)

}

Result:

To(59711053-b512-4601-9f70-e41c4b05a694,130971f2-7720-4707-b81b-f7c0cbdd6c25,meh)

Notice if I rename the other uuid field to something else then it works correctly. Chimney 0.8.5.

I saw the ignored #449 bug too. Just worth mentioning that in our domain setUuid wasn't considered a setter, but rather a uuid of a set of entities. Anyway, it shouldn't allow to compile it silently, if using "setter"-like names is prohibited.

Tvaroh avatar Feb 05 '24 09:02 Tvaroh