-
-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Labels
enhancementrelatively easy but not smallTask with requires some knowlege and writing more code, but not the intimate knoledge about macrosTask with requires some knowlege and writing more code, but not the intimate knoledge about macros
Description
Discussed in #761
Originally posted by nedsociety July 14, 2025
Since Scala 3.7 this is now enabled by default, so it'd be nice to have derivations available for named tuples <=> products
transformation.
//> using scala 3.7.1
//> using dep io.scalaland::chimney:1.8.3
import io.scalaland.chimney.dsl.*
case class C(a: Int, b: Int)
(b=2, a=1).transformInto[C]
Currently it errors with missing derivation:
-- Error: ----------------------------------------------------------------------
1 |(b=2, a=1).transformInto[C]
| ^
|Chimney can't derive transformation from scala.NamedTuple.NamedTuple[scala.Tuple2["b", "a"], scala.Tuple2[scala.Int, scala.Int]] to rs$line$2.C
|
|rs$line$2.C
| a: scala.Int - no accessor named a in source type scala.NamedTuple.NamedTuple[scala.Tuple2["b", "a"], scala.Tuple2[scala.Int, scala.Int]]
| b: scala.Int - no accessor named b in source type scala.NamedTuple.NamedTuple[scala.Tuple2["b", "a"], scala.Tuple2[scala.Int, scala.Int]]
|
|Consult https://chimney.readthedocs.io for usage examples.
|
1 error found
The issue seem to be this piece of code
Lines 78 to 81 in a55f1df
val usePositionBasedMatching = | |
Type[From].isTuple || Type[To].isTuple || ctx.config.filterCurrentOverridesForFallbacks.exists { | |
case TransformerOverride.Fallback(runtimeData) => runtimeData.Underlying.isTuple | |
} |
It assumes that all tuples should be handled in position-based way, which does not work for named tuples. So named tuples would have to be excluded from this case. Then we can see whether NamedTuples methods are visible to macros.
Testing it might be tricky since 1.x is on 3.3, so they would have to be written on 2.0.0-development
branch, and the solution would either have to be implemented on that branch, or ported to it.
Metadata
Metadata
Assignees
Labels
enhancementrelatively easy but not smallTask with requires some knowlege and writing more code, but not the intimate knoledge about macrosTask with requires some knowlege and writing more code, but not the intimate knoledge about macros