Skip to content

Commit ee8760c

Browse files
committed
Do not hardcode primitive liftables
1 parent 0e5b3e8 commit ee8760c

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ class Definitions {
635635
@tu lazy val QuoteContextModule: Symbol = QuoteContextClass.companionModule
636636
@tu lazy val QuoteContext_macroContext: Symbol = QuoteContextModule.requiredMethod("macroContext")
637637

638+
@tu lazy val LiftableClass: ClassSymbol = ctx.requiredClass("scala.quoted.Liftable")
638639
@tu lazy val LiftableModule: Symbol = ctx.requiredModule("scala.quoted.Liftable")
639640

640641
@tu lazy val InternalQuotedModule: Symbol = ctx.requiredModule("scala.internal.Quoted")

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,24 +206,19 @@ class ReifyQuotes extends MacroTransform {
206206
qctx
207207
}
208208

209-
def liftedValue[T](value: T, name: TermName) =
210-
ref(defn.LiftableModule)
211-
.select(name).appliedToType(originalTp)
212-
.select("toExpr".toTermName).appliedTo(Literal(Constant(value)))
209+
def liftedValue[T](const: Constant) = {
210+
val ltp = defn.LiftableClass.typeRef.appliedTo(ConstantType(const))
211+
val liftable = ctx.typer.inferImplicitArg(ltp, body.span)
212+
if (liftable.tpe.isInstanceOf[SearchFailureType])
213+
ctx.error(ctx.typer.missingArgMsg(liftable, ltp, "Could no optimize constant in quote"), ctx.source.atSpan(body.span))
214+
liftable.select("toExpr".toTermName).appliedTo(Literal(const))
215+
}
213216

214217
def pickleAsValue[T](value: T) =
215218
value match {
216219
case null => ref(defn.QuotedExprModule).select("nullExpr".toTermName)
217220
case _: Unit => ref(defn.QuotedExprModule).select("unitExpr".toTermName)
218-
case _: Boolean => liftedValue(value, "Liftable_Boolean_delegate".toTermName)
219-
case _: Byte => liftedValue(value, "Liftable_Byte_delegate".toTermName)
220-
case _: Short => liftedValue(value, "Liftable_Short_delegate".toTermName)
221-
case _: Int => liftedValue(value, "Liftable_Int_delegate".toTermName)
222-
case _: Long => liftedValue(value, "Liftable_Long_delegate".toTermName)
223-
case _: Float => liftedValue(value, "Liftable_Float_delegate".toTermName)
224-
case _: Double => liftedValue(value, "Liftable_Double_delegate".toTermName)
225-
case _: Char => liftedValue(value, "Liftable_Char_delegate".toTermName)
226-
case _: String => liftedValue(value, "Liftable_String_delegate".toTermName)
221+
case _ => liftedValue(Constant(value))
227222
}
228223

229224
def pickleAsTasty() = {

0 commit comments

Comments
 (0)