From 16d1f88653c6226709fbca609e4cd1dd12cac066 Mon Sep 17 00:00:00 2001 From: Mateusz Kubuszok Date: Fri, 15 Sep 2023 13:29:44 +0200 Subject: [PATCH] Ignore implicit summoning when overrides are not empty --- .../compiletime/derivation/transformer/Configurations.scala | 6 +++++- .../transformer/rules/TransformImplicitRuleModule.scala | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Configurations.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Configurations.scala index 163c3dbd0..2fb2869c8 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Configurations.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/Configurations.scala @@ -95,7 +95,8 @@ private[compiletime] trait Configurations { this: Derivation => // }}} copy( preventResolutionForTypes = None, - fieldOverrides = Map.empty + fieldOverrides = Map.empty, + coproductOverrides = Map.empty ) def addFieldOverride(fieldName: String, fieldOverride: RuntimeFieldOverride): TransformerConfig = @@ -108,6 +109,9 @@ private[compiletime] trait Configurations { this: Derivation => ): TransformerConfig = copy(coproductOverrides = coproductOverrides + ((instanceType, targetType) -> coproductOverride)) + def areOverridesEmpty: Boolean = + fieldOverrides.isEmpty && coproductOverrides.isEmpty + def withDefinitionScope(defScope: (??, ??)): TransformerConfig = copy(preventResolutionForTypes = Some(defScope)) diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformImplicitRuleModule.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformImplicitRuleModule.scala index 2ca41aff4..5fd70dd34 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformImplicitRuleModule.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformImplicitRuleModule.scala @@ -10,6 +10,10 @@ private[compiletime] trait TransformImplicitRuleModule { this: Derivation => def expand[From, To](implicit ctx: TransformationContext[From, To]): DerivationResult[Rule.ExpansionResult[To]] = ctx match { + case _ if !ctx.config.areOverridesEmpty => + DerivationResult.log( + "Configuration has defined overrides - implicit summoning is skipped" + ) >> DerivationResult.attemptNextRule case TransformationContext.ForTotal(src) => summonTransformerSafe[From, To].fold(DerivationResult.attemptNextRule[To]) { totalTransformer => // We're constructing: