From 175385055b913d5cbc3f0afd16e8c17fce7d0d98 Mon Sep 17 00:00:00 2001 From: Alexander Ioffe Date: Tue, 21 May 2024 18:13:53 -0400 Subject: [PATCH] Widen Quats during type-checking (#452) --- .../scala/io/getquill/quat/QuatMaking.scala | 33 ++++++++++--------- .../io/getquill/util/ProtoMessages.scala | 1 + 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/quill-sql/src/main/scala/io/getquill/quat/QuatMaking.scala b/quill-sql/src/main/scala/io/getquill/quat/QuatMaking.scala index e81c88ca..0a86a11c 100644 --- a/quill-sql/src/main/scala/io/getquill/quat/QuatMaking.scala +++ b/quill-sql/src/main/scala/io/getquill/quat/QuatMaking.scala @@ -16,6 +16,7 @@ import io.getquill.generic.GenericDecoder import io.getquill.util.Format import io.getquill.generic.DecodingType import io.getquill.Quoted +import io.getquill.util.ProtoMessages inline def quatOf[T]: Quat = ${ QuatMaking.quatOfImpl[T] } @@ -72,7 +73,7 @@ trait QuatMaking extends QuatMakingBase { import quotes.reflect._ // TODO Try summoning 'value' to know it's a value for sure if a encoder doesn't exist? def encoderComputation() = { - tpe.asType match { + tpe.widen.asType match { // If an identifier in the Quill query is has a Encoder/Decoder pair, we treat it as a value i.e. Quat.Value is assigned as it's Quat. // however, what do we do if there is only one. Say for Name(value: String), Person(name: Name, age: Int) there is a Name-Decoder // but no Name-encoder. It is difficult to know whether to treat p.name in `query[Person].map(p => p.name)` as a Quat Value or Product. @@ -88,22 +89,24 @@ trait QuatMaking extends QuatMakingBase { (Expr.summon[GenericEncoder[t, _, _]], Expr.summon[GenericDecoder[_, _, t, DecodingType.Specific]]) match { case (Some(_), Some(_)) => true case (Some(enc), None) => - report.warning( - s"A Encoder:\n" + - s"${Format.Expr(enc)}\n" + - s"was found for the type ${Format.TypeOf[t]} but not a decoder so this type will " + - s"be treated as a value. To avoid potential problems it is preferable to define " + - s"both an encoder and a decoder for all types used in Quill Queries." - ) + if (ProtoMessages.aggressiveQuatChecking) + report.warning( + s"A Encoder:\n" + + s"${Format.Expr(enc)}\n" + + s"was found for the type ${Format.TypeOf[t]} but not a decoder so this type will " + + s"be treated as a value. To avoid potential problems it is preferable to define " + + s"both an encoder and a decoder for all types used in Quill Queries." + ) true case (None, Some(dec)) => - report.warning( - s"A Decoder:\n" + - s"${Format.Expr(dec)}\n " + - s"was found for the type ${Format.TypeOf[t]} but not a encoder so this type will be " + - s"treated as a value. To avoid potential problems it is preferable to define " + - s"both an encoder and a decoder for all types used in Quill Queries." - ) + if (ProtoMessages.aggressiveQuatChecking) + report.warning( + s"A Decoder:\n" + + s"${Format.Expr(dec)}\n " + + s"was found for the type ${Format.TypeOf[t]} but not a encoder so this type will be " + + s"treated as a value. To avoid potential problems it is preferable to define " + + s"both an encoder and a decoder for all types used in Quill Queries." + ) true case (None, None) => false } diff --git a/quill-sql/src/main/scala/io/getquill/util/ProtoMessages.scala b/quill-sql/src/main/scala/io/getquill/util/ProtoMessages.scala index 5e39050c..31de723f 100644 --- a/quill-sql/src/main/scala/io/getquill/util/ProtoMessages.scala +++ b/quill-sql/src/main/scala/io/getquill/util/ProtoMessages.scala @@ -19,5 +19,6 @@ object ProtoMessages { private[getquill] def serializeAst = cache("quill.ast.serialize", variable("quill.ast.serialize", "quill_ast_serialize", "true").toBoolean) private[getquill] def maxQuatFields = cache("quill.quat.tooManyFields", variable("quill.quat.tooManyFields", "quill_quat_tooManyFields", "4").toInt) private[getquill] def errorDetail = cache("quill.error.detail", variable("quill.error.detail", "quill_error_detail", "false").toBoolean) + private[getquill] def aggressiveQuatChecking = cache("quill.quat.aggresive", variable("quill.quat.aggresive", "quill_quat_aggresive", "false").toBoolean) } // end ProtoMessages