Skip to content

Commit

Permalink
Test withFieldComputedFrom/withFieldComputedFromPartial and withField…
Browse files Browse the repository at this point in the history
…Renamed for nested sealed
  • Loading branch information
MateuszKubuszok committed Jan 5, 2025
1 parent c393c77 commit 3ee9d8e
Show file tree
Hide file tree
Showing 4 changed files with 430 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,10 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio
case Nil =>
whenAbsent
case runtimeFieldOverride :: Nil =>
import FromOperation.{Computed, ComputedPartial}
import io.scalaland.chimney.internal.compiletime.DerivationError.TransformerError as TError
import io.scalaland.chimney.internal.compiletime.NotSupportedOperationFromPath as NotSupportedFrom
useOverride[From, To, CtorParam](toName, runtimeFieldOverride).recoverWith {
case DerivationErrors(TError(NotSupportedFrom(Computed | ComputedPartial, `toName`, _, _)), Vector()) =>
case DerivationErrors(TError(NotSupportedFrom(_, `toName`, _, _)), Vector()) =>
// If we cannot extract value in .withFieldComputedFrom/.withFieldComputedPartialFrom, it might be because
// path is matching on TargetSide, but SourceSide requires recursion, TransformationContext update,
// and then matching on some other rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ private[compiletime] trait TransformSealedHierarchyToSealedHierarchyRuleModule {
case (_, TransformerOverride.Computed(_, targetPath, _)) => targetPath == ctx.currentTgt
case (_, TransformerOverride.ComputedPartial(_, targetPath, _)) => targetPath == ctx.currentTgt
case (_, TransformerOverride.Renamed(_, targetPath)) =>
targetPath match {
case Path.AtSubtype(someTo, root) => someTo.Underlying <:< Type[To] && root == ctx.currentTgt
case _ => false
targetPath.drop(ctx.currentTgt) match {
case Some(Path.AtSubtype(someTo, root)) => someTo.Underlying <:< Type[To] && root == Path.Root
case _ => false
}
}
.toList
Expand Down Expand Up @@ -105,7 +105,7 @@ private[compiletime] trait TransformSealedHierarchyToSealedHierarchyRuleModule {
runtimeData.asInstanceOfExpr[From => partial.Result[To]].apply(fromExpr)
)
case TransformerOverride.Renamed(_, targetPath) =>
val Path.AtSubtype(someTo, _) = targetPath: @unchecked
val Some(Path.AtSubtype(someTo, _)) = targetPath.drop(ctx.currentTgt): @unchecked
// We're constructing:
// case someFromExpr: $someFrom => $derivedToSubtype.asInstance
import someTo.Underlying as SomeTo
Expand Down
Loading

0 comments on commit 3ee9d8e

Please sign in to comment.