From ae098a6311e2a7cf4f9574cdd3e9cb3ebd92d222 Mon Sep 17 00:00:00 2001 From: Mateusz Kubuszok Date: Tue, 2 Jul 2024 14:45:37 +0200 Subject: [PATCH] Turn off coverage for all assertionFailed in macros (since most of them are errors that we don't expect to reproduce but not fix), refactor defaults a bit --- .../internal/compiletime/TypesPlatform.scala | 6 +++++- .../datatypes/ProductTypesPlatform.scala | 19 +++++++++++-------- .../internal/compiletime/TypesPlatform.scala | 7 ++++++- .../datatypes/ProductTypesPlatform.scala | 6 ++++++ .../chimney/internal/compiletime/Exprs.scala | 2 ++ .../compiletime/datatypes/ProductTypes.scala | 4 ++++ .../derivation/codec/CodecMacros.scala | 2 +- .../derivation/iso/IsoMacros.scala | 2 +- .../derivation/patcher/PatcherMacros.scala | 2 +- .../transformer/TransformerMacros.scala | 2 +- .../derivation/codec/CodecMacros.scala | 2 +- .../derivation/iso/IsoMacros.scala | 2 +- .../derivation/patcher/PatcherMacros.scala | 2 +- .../transformer/TransformerMacros.scala | 2 +- .../derivation/patcher/Configurations.scala | 8 +++++--- .../derivation/patcher/Derivation.scala | 2 ++ .../transformer/Configurations.scala | 10 +++++----- .../TransformProductToProductRuleModule.scala | 4 ++++ .../rules/TransformationRules.scala | 2 ++ 19 files changed, 60 insertions(+), 26 deletions(-) diff --git a/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala b/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala index 260011dfd..e1a35360b 100644 --- a/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala +++ b/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala @@ -144,7 +144,11 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo .value .asInstanceOf[String] ) - .getOrElse(assertionFailed(s"Invalid string literal type: ${prettyPrint(S)}")) + .getOrElse { + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation + assertionFailed(s"Invalid string literal type: ${prettyPrint(S)}") + // $COVERAGE-ON$ + } def isTuple[A](A: Type[A]): Boolean = A.tpe.typeSymbol.fullName.startsWith("scala.Tuple") diff --git a/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypesPlatform.scala b/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypesPlatform.scala index 613a091ee..d810cd51d 100644 --- a/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypesPlatform.scala +++ b/chimney-macro-commons/src/main/scala-2/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypesPlatform.scala @@ -118,7 +118,9 @@ trait ProductTypesPlatform extends ProductTypes { this: DefinitionsPlatform => } else if (isPOJO[A]) { val primaryConstructor = Option(sym).filter(_.isClass).map(_.asClass.primaryConstructor).filter(_.isPublic).getOrElse { + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation assertionFailed(s"Expected public constructor of ${Type.prettyPrint[A]}") + // $COVERAGE-ON$ } val paramss = paramListsOf(A, primaryConstructor) val paramNames = paramss.flatMap(_.map(param => param -> getDecodedName(param))).toMap @@ -129,19 +131,20 @@ trait ProductTypesPlatform extends ProductTypes { this: DefinitionsPlatform => val defaultIdx = idx + 1 // defaults are 1-indexed val scala2default = caseClassApplyDefaultScala2(defaultIdx) val scala3default = caseClassApplyDefaultScala3(defaultIdx) - val scala2new = classNewDefaultScala2(defaultIdx) + val newDefault = classNewDefaultScala2(defaultIdx) + val defaults = List(scala2default, scala3default, newDefault) val foundDefault = companion.typeSignature.decls .to(List) .collectFirst { - case method if getDecodedName(method) == scala2default => TermName(scala2default) - case method if getDecodedName(method) == scala3default => TermName(scala3default) - case method if getDecodedName(method) == scala2new => TermName(scala2new) + case method if defaults.contains(getDecodedName(method)) => method } - .getOrElse( + .getOrElse { + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation assertionFailed( - s"Expected that ${Type.prettyPrint[A]}'s constructor parameter `$param` would have default value: attempted `$scala2default`, `$scala3default` and `$scala2new`, found: ${companion.typeSignature.decls}" + s"Expected that ${Type.prettyPrint[A]}'s constructor parameter `$param` would have default value: attempted `$scala2default`, `$scala3default` and `$newDefault`, found: ${companion.typeSignature.decls}" ) - ) + // $COVERAGE-ON$ + } paramNames(param) -> q"$companion.$foundDefault" }.toMap val constructorParameters = ListMap.from(paramss.flatMap(_.map { param => @@ -276,7 +279,7 @@ trait ProductTypesPlatform extends ProductTypes { this: DefinitionsPlatform => .dropWhile { case (x, y) => x == y } .takeWhile(_._1 != NoSymbol) .map(_._1.name.toTermName) - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation if (path.isEmpty) assertionFailed(s"Cannot find a companion for ${Type.prettyPrint[A]}") else c.typecheck(path.foldLeft[Tree](Ident(path.next()))(Select(_, _)), silent = true).symbol // $COVERAGE-ON$ diff --git a/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala b/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala index bcf3d07d6..26bfb954b 100644 --- a/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala +++ b/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/TypesPlatform.scala @@ -62,9 +62,11 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo typeArgumentByName // unknown case out => + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed( s"Constructor of ${Type.prettyPrint(fromUntyped[Any](tpe))} has unrecognized/unsupported format of type: $out" ) + // $COVERAGE-ON$ } /** Applies type arguments from supertype to subtype if there are any */ @@ -215,7 +217,10 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo def extractStringSingleton[S <: String](S: Type[S]): String = quoted.Type.valueOfConstant[S](using S) match { case Some(str) => str - case None => assertionFailed(s"Invalid string literal type: ${prettyPrint(S)}") + case None => + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation + assertionFailed(s"Invalid string literal type: ${prettyPrint(S)}") + // $COVERAGE-ON$ } def isTuple[A](A: Type[A]): Boolean = TypeRepr.of(using A).typeSymbol.fullName.startsWith("scala.Tuple") diff --git a/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypesPlatform.scala b/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypesPlatform.scala index 69305e95b..914eacfff 100644 --- a/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypesPlatform.scala +++ b/chimney-macro-commons/src/main/scala-3/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypesPlatform.scala @@ -143,7 +143,9 @@ trait ProductTypesPlatform extends ProductTypes { this: DefinitionsPlatform => val primaryConstructor = Option(sym.primaryConstructor).filter(_.isPublic).getOrElse { + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed(s"Expected public constructor of ${Type.prettyPrint[A]}") + // $COVERAGE-ON$ } val paramss = paramListsOf(A, primaryConstructor) val paramNames = paramss.flatMap(_.map(param => param -> param.name)).toMap @@ -155,9 +157,11 @@ trait ProductTypesPlatform extends ProductTypes { this: DefinitionsPlatform => val scala3default = caseClassApplyDefaultScala3(idx + 1) val default = (mod.declaredMethod(scala2default) ++ mod.declaredMethod(scala3default)).headOption.getOrElse { + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed( s"Expected that ${Type.prettyPrint[A]}'s constructor parameter `$param` would have default value: attempted `$scala2default` and `$scala3default`, found: ${mod.declaredMethods}" ) + // $COVERAGE-ON$ } paramNames(param) -> Ref(mod).select(default) }.toMap @@ -262,7 +266,9 @@ trait ProductTypesPlatform extends ProductTypes { this: DefinitionsPlatform => val fnType = fnTypeByArity.getOrElse( paramList.size, // TODO: handle FunctionXXL + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed(s"Expected arity between 0 and 22 into ${Type.prettyPrint[A]}, got: ${paramList.size}") + // $COVERAGE-ON$ ) val paramTypes = paramList.view.values.map(p => TypeRepr.of(using p.Underlying)).toVector diff --git a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/Exprs.scala b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/Exprs.scala index 9fc1d2cf9..fbabd5384 100644 --- a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/Exprs.scala +++ b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/Exprs.scala @@ -115,7 +115,9 @@ private[compiletime] trait Exprs { this: Definitions => def summonImplicit[A: Type]: Option[Expr[A]] def summonImplicitUnsafe[A: Type]: Expr[A] = summonImplicit[A].getOrElse { + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed(s"Implicit not found: ${Type.prettyPrint[A]}") + // $COVERAGE-ON$ } // Implementations of Expr extension methods diff --git a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypes.scala b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypes.scala index ca35ca879..5eef3a425 100644 --- a/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypes.scala +++ b/chimney-macro-commons/src/main/scala/io/scalaland/chimney/internal/compiletime/datatypes/ProductTypes.scala @@ -128,11 +128,13 @@ trait ProductTypes { this: Definitions => ): (Product.Arguments, Product.Arguments) = { val missingArguments = parameters.filter(settersCanBeIgnored).keySet diff arguments.keySet if (missingArguments.nonEmpty) { + // $COVERAGE-OFF$should never happen unless we messed up val missing = missingArguments.mkString(", ") val provided = arguments.keys.mkString(", ") assertionFailed( s"Constructor of ${Type.prettyPrint[A]} expected arguments: $missing but they were not provided, what was provided: $provided" ) + // $COVERAGE-ON$ } parameters.foreach { case (name, param) => @@ -140,10 +142,12 @@ trait ProductTypes { this: Definitions => // setter might be absent, so we cannot assume that argument for it is in a map arguments.get(name).foreach { argument => if (!(argument.Underlying <:< Param)) { + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed( s"Constructor of ${Type.prettyPrint[A]} expected expr for parameter $param of type ${Type .prettyPrint[param.Underlying]}, instead got ${Expr.prettyPrint(argument.value)} ${Type.prettyPrint(argument.Underlying)}" ) + // $COVERAGE-ON$ } } } diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/codec/CodecMacros.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/codec/CodecMacros.scala index 5a281b8c4..278fcd050 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/codec/CodecMacros.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/codec/CodecMacros.scala @@ -102,7 +102,7 @@ final class CodecMacros(val c: blackbox.Context) extends DerivationPlatform with ) Expr.summonImplicit(transformerConfigurationType).getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Can't locate implicit TransformerConfiguration!") // $COVERAGE-ON$ } diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/iso/IsoMacros.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/iso/IsoMacros.scala index de7f39bb5..94b09b9b6 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/iso/IsoMacros.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/iso/IsoMacros.scala @@ -102,7 +102,7 @@ final class IsoMacros(val c: blackbox.Context) extends DerivationPlatform with G ) Expr.summonImplicit(transformerConfigurationType).getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Can't locate implicit TransformerConfiguration!") // $COVERAGE-ON$ } diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/patcher/PatcherMacros.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/patcher/PatcherMacros.scala index a4e24fe3e..67781cef8 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/patcher/PatcherMacros.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/patcher/PatcherMacros.scala @@ -79,7 +79,7 @@ final class PatcherMacros(val c: blackbox.Context) extends DerivationPlatform wi ) Expr.summonImplicit(patcherConfigurationType).getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Can't locate implicit PatcherConfiguration!") // $COVERAGE-ON$ } diff --git a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/transformer/TransformerMacros.scala b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/transformer/TransformerMacros.scala index cd4e355e3..5349a3dba 100644 --- a/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/transformer/TransformerMacros.scala +++ b/chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/derivation/transformer/TransformerMacros.scala @@ -175,7 +175,7 @@ final class TransformerMacros(val c: blackbox.Context) extends DerivationPlatfor ) Expr.summonImplicit(transformerConfigurationType).getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Can't locate implicit TransformerConfiguration!") // $COVERAGE-ON$ } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/codec/CodecMacros.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/codec/CodecMacros.scala index e8abd6309..f781f0017 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/codec/CodecMacros.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/codec/CodecMacros.scala @@ -74,7 +74,7 @@ final class CodecMacros(q: Quotes) extends DerivationPlatform(q) with Gateway { val implicitScopeConfig = scala.quoted.Expr .summon[io.scalaland.chimney.dsl.TransformerConfiguration[? <: runtime.TransformerFlags]] .getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Can't locate implicit TransformerConfiguration!") // $COVERAGE-ON$ } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/iso/IsoMacros.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/iso/IsoMacros.scala index afcd0969f..38523e780 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/iso/IsoMacros.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/iso/IsoMacros.scala @@ -74,7 +74,7 @@ final class IsoMacros(q: Quotes) extends DerivationPlatform(q) with Gateway { val implicitScopeConfig = scala.quoted.Expr .summon[io.scalaland.chimney.dsl.TransformerConfiguration[? <: runtime.TransformerFlags]] .getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Can't locate implicit TransformerConfiguration!") // $COVERAGE-ON$ } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/patcher/PatcherMacros.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/patcher/PatcherMacros.scala index b78e27167..fbdb88ad5 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/patcher/PatcherMacros.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/patcher/PatcherMacros.scala @@ -35,7 +35,7 @@ final class PatcherMacros(q: Quotes) extends DerivationPlatform(q) with Gateway val implicitScopeConfig = scala.quoted.Expr .summon[io.scalaland.chimney.dsl.PatcherConfiguration[? <: runtime.PatcherFlags]] .getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Can't locate implicit PatcherConfiguration!") // $COVERAGE-ON$ } diff --git a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/transformer/TransformerMacros.scala b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/transformer/TransformerMacros.scala index 7e6d0b891..83a23d755 100644 --- a/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/transformer/TransformerMacros.scala +++ b/chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/derivation/transformer/TransformerMacros.scala @@ -75,7 +75,7 @@ final class TransformerMacros(q: Quotes) extends DerivationPlatform(q) with Gate val implicitScopeConfig = scala.quoted.Expr .summon[io.scalaland.chimney.dsl.TransformerConfiguration[? <: runtime.TransformerFlags]] .getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Can't locate implicit TransformerConfiguration!") // $COVERAGE-ON$ } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Configurations.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Configurations.scala index 30e7fd8eb..912ac273c 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Configurations.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Configurations.scala @@ -18,7 +18,7 @@ private[compiletime] trait Configurations { this: Derivation => } else if (Type[Flag] =:= ChimneyType.PatcherFlags.Flags.MacrosLogging) { copy(displayMacrosLogging = value) } else { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError(s"Invalid internal PatcherFlags type shape: ${Type[Flag]}!") // $COVERAGE-ON$ } @@ -79,7 +79,7 @@ private[compiletime] trait Configurations { this: Derivation => import flag.Underlying as Flag, flags.Underlying as Flags2 extractTransformerFlags[Flags2](defaultFlags).setBoolFlag[Flag](value = false) case _ => - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError(s"Invalid internal PatcherFlags type shape: ${Type.prettyPrint[Flags]}!") // $COVERAGE-ON$ } @@ -87,8 +87,10 @@ private[compiletime] trait Configurations { this: Derivation => private def extractPatcherConfig[Tail <: runtime.PatcherOverrides: Type](): PatcherConfiguration = Type[Tail] match { case empty if empty =:= ChimneyType.PatcherOverrides.Empty => PatcherConfiguration() - case _ => + case _ => + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError(s"Invalid internal PatcherOverrides type shape: ${Type.prettyPrint[Tail]}!!") + // $COVERAGE-ON$ } } } diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Derivation.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Derivation.scala index 2d0fd00b0..b9bd88270 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Derivation.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/patcher/Derivation.scala @@ -105,9 +105,11 @@ private[compiletime] trait Derivation ) } case _ => + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed( s"Expected both types to be options, got ${Type.prettyPrint[PatchGetter]} and ${Type.prettyPrint[TargetParam]}" ) + // $COVERAGE-ON$ } } else if (PatchGetter <:< TargetParam) { DerivationResult.pure(Some(patchGetterExpr)) 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 ac6ef7f4b..7f2ed68d1 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 @@ -384,7 +384,7 @@ private[compiletime] trait Configurations { this: Derivation => Some(dsls.PreferPartialTransformer) ) else { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError("Invalid ImplicitTransformerPreference type!!") // $COVERAGE-ON$ } @@ -417,7 +417,7 @@ private[compiletime] trait Configurations { this: Derivation => extractTransformerFlags[Flags2](defaultFlags).setBoolFlag[Flag](value = false) } case _ => - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError(s"Invalid internal TransformerFlags type shape: ${Type.prettyPrint[Flags]}!") // $COVERAGE-ON$ } @@ -498,7 +498,7 @@ private[compiletime] trait Configurations { this: Derivation => TransformerOverride.RenamedTo(extractPath[ToPath]) ) case _ => - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError(s"Invalid internal TransformerOverrides type shape: ${Type.prettyPrint[Tail]}!!") // $COVERAGE-ON$ } @@ -525,7 +525,7 @@ private[compiletime] trait Configurations { this: Derivation => import init.Underlying as PathType2 extractPath[PathType2].everyMapValue case _ => - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError(s"Invalid internal Path shape: ${Type.prettyPrint[PathType]}!!") // $COVERAGE-ON$ } @@ -553,7 +553,7 @@ private[compiletime] trait Configurations { this: Derivation => .reverse // ...and this is: "foo.bar.baz$", "foo.bar$baz$", "foo$bar$baz$" .collectFirst { case Comparison(value) => value } // attempts: top-level object, object in object, etc .getOrElse { - // $COVERAGE-OFF$ + // $COVERAGE-OFF$should never happen unless someone mess around with type-level representation reportError( s"Invalid TransformerNamesComparison type - only (case) objects are allowed, and only the ones defined as top-level or in top-level objects, got: ${Type .prettyPrint[Comparison]}!!!" diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformProductToProductRuleModule.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformProductToProductRuleModule.scala index 97faaae85..16cfffd00 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformProductToProductRuleModule.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformProductToProductRuleModule.scala @@ -516,7 +516,9 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio import res1.{Underlying as Res1, value as result1Expr}, res2.{Underlying as Res2, value as result2Expr} ctx match { case TransformationContext.ForTotal(_) => + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed("Expected partial while got total") + // $COVERAGE-ON$ case TransformationContext.ForPartial(_, failFast) => TransformationExpr.fromPartial( ChimneyExpr.PartialResult.map2( @@ -667,7 +669,9 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio ctx match { case TransformationContext.ForTotal(_) => + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed("Expected partial, got total") + // $COVERAGE-ON$ case TransformationContext.ForPartial(_, failFast) => // Finally, we are combining: // if (${ failFast }) { diff --git a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformationRules.scala b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformationRules.scala index ba208fa9a..3584e44dc 100644 --- a/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformationRules.scala +++ b/chimney/src/main/scala/io/scalaland/chimney/internal/compiletime/derivation/transformer/rules/TransformationRules.scala @@ -103,9 +103,11 @@ private[compiletime] trait TransformationRules { this: Derivation => final def isPartial: Boolean = fold(_ => false)(_ => true) final def ensureTotal: Expr[A] = fold(identity) { expr => + // $COVERAGE-OFF$should never happen unless we messed up assertionFailed( s"Derived partial.Result expression where total Transformer expects direct value: ${Expr.prettyPrint(expr)}" ) + // $COVERAGE-ON$ } final def ensurePartial: Expr[partial.Result[A]] = fold { expr => implicit val A: Type[A] = Expr.typeOf(expr)