Skip to content

Commit 8f25235

Browse files
committed
Normalize contextualization of quotes an liftables
* Redefine quote as ```def `'`[T](e: T): given QuoteContext => Expr[T]``` * Redefine `Liftable.toExpr` as `def toExpr(x: T): given QuoteContext => Expr[T]`
1 parent dd449e7 commit 8f25235

30 files changed

+83
-107
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,9 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
838838
* The result can be the contents of a term or type quote, which
839839
* will return a term or type tree respectively.
840840
*/
841-
def unapply(tree: tpd.Tree)(implicit ctx: Context): Option[(tpd.Tree, tpd.Tree)] = tree match {
842-
case Apply(Apply(_, quoted :: Nil), qctx :: Nil) if tree.symbol.isQuote => Some((quoted, qctx))
843-
case TypeApply(_, quoted :: Nil) if tree.symbol.isQuote => Some((quoted, Literal(Constants.Constant(null))))
841+
def unapply(tree: tpd.Tree)(implicit ctx: Context): Option[tpd.Tree] = tree match {
842+
case Apply(_, quoted :: Nil) if tree.symbol.isQuote => Some(quoted)
843+
case TypeApply(_, quoted :: Nil) if tree.symbol.isQuote => Some(quoted)
844844
case _ => None
845845
}
846846
}
@@ -858,29 +858,6 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
858858
}
859859
}
860860

861-
/** Extractors for splices */
862-
object SplicedExpr {
863-
/** Extracts the content of a spliced tree.
864-
* The result can be the contents of a term or type splice, which
865-
* will return a term or type tree respectively.
866-
*/
867-
def unapply(tree: tpd.Tree)(implicit ctx: Context): Option[tpd.Tree] = tree match {
868-
case tree: tpd.Apply if tree.symbol.isSplice => Some(tree.args.head)
869-
case _ => None
870-
}
871-
}
872-
873-
/** Extractors for splices */
874-
object SplicedType {
875-
/** Extracts the content of a spliced tree.
876-
* The result can be the contents of a term or type splice, which
877-
* will return a term or type tree respectively.
878-
*/
879-
def unapply(tree: tpd.Tree)(implicit ctx: Context): Option[tpd.Tree] = tree match {
880-
case tree: tpd.Select if tree.symbol.isSplice => Some(tree.qualifier)
881-
case _ => None
882-
}
883-
}
884861
}
885862

886863
object TreeInfo {

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
366366
keywordStr("throw ") ~ toText(args.head)
367367
}
368368
else if (!printDebug && fun.hasType && fun.symbol == defn.InternalQuoted_exprQuote) {
369-
val Apply(_, args2) = fun
370-
keywordStr("'{") ~ toTextGlobal(args2, ", ") ~ keywordStr("}")
369+
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
371370
} else if (!printDebug && fun.hasType && fun.symbol == defn.InternalQuoted_exprSplice)
372371
keywordStr("${") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
373372
else if (app.isGivenApply && !homogenizedView)

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
4343
}
4444

4545
/** Transform quoted trees while maintaining phase correctness */
46-
override protected def transformQuotation(body: Tree, qctx: Tree, quote: Tree)(implicit ctx: Context): Tree = {
46+
override protected def transformQuotation(body: Tree, quote: Tree)(implicit ctx: Context): Tree = {
4747
val body1 = transform(body)(quoteContext)
48-
val qctx1 = transform(qctx)
49-
super.transformQuotation(body1, qctx1, quote)
48+
super.transformQuotation(body1, quote)
5049
}
5150

5251
/** Transform splice
@@ -76,7 +75,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
7675
protected def checkLevel(tree: Tree)(implicit ctx: Context): Tree = {
7776
def checkTp(tp: Type): Type = checkType(tree.sourcePos).apply(tp)
7877
tree match {
79-
case Quoted(_, _) | Spliced(_) =>
78+
case Quoted(_) | Spliced(_) =>
8079
tree
8180
case tree: RefTree if tree.symbol.isAllOf(InlineParam) =>
8281
tree

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,39 +175,39 @@ class ReifyQuotes extends MacroTransform {
175175
* `scala.quoted.Unpickler.unpickleExpr` that matches `tpe` with
176176
* core and splices as arguments.
177177
*/
178-
override protected def transformQuotation(body: Tree, qctx: Tree, quote: Tree)(implicit ctx: Context): Tree = {
178+
override protected def transformQuotation(body: Tree, quote: Tree)(implicit ctx: Context): Tree = {
179179
val isType = quote.symbol eq defn.InternalQuoted_typeQuote
180180
if (level > 0) {
181181
val body1 = nested(isQuote = true).transform(body)(quoteContext)
182-
super.transformQuotation(body1, qctx, quote)
182+
super.transformQuotation(body1, quote)
183183
}
184184
else body match {
185185
case body: RefTree if isCaptured(body.symbol, level + 1) =>
186186
// Optimization: avoid the full conversion when capturing `x`
187187
// in '{ x } to '{ ${x$1} } and go directly to `x$1`
188-
capturers(body.symbol)(body).select(nme.apply).appliedTo(qctx)
188+
capturers(body.symbol)(body)
189189
case _=>
190190
val (body1, splices) = nested(isQuote = true).splitQuote(body)(quoteContext)
191191
if (level == 0) {
192192
val body2 =
193193
if (body1.isType) body1
194194
else Inlined(Inliner.inlineCallTrace(ctx.owner, quote.sourcePos), Nil, body1)
195-
pickledQuote(body2, splices, qctx, body.tpe, isType).withSpan(quote.span)
195+
pickledQuote(body2, splices, body.tpe, isType).withSpan(quote.span)
196196
}
197197
else {
198198
body
199199
}
200200
}
201201
}
202202

203-
private def pickledQuote(body: Tree, splices: List[Tree], qctx: Tree, originalTp: Type, isType: Boolean)(implicit ctx: Context) = {
203+
private def pickledQuote(body: Tree, splices: List[Tree], originalTp: Type, isType: Boolean)(implicit ctx: Context) = {
204204
def liftedValue[T](value: T, name: TermName) =
205-
ref(defn.LiftableModule).select(name).select("toExpr".toTermName).appliedTo(Literal(Constant(value))).appliedTo(qctx)
205+
ref(defn.LiftableModule).select(name).select("toExpr".toTermName).appliedTo(Literal(Constant(value)))
206206

207207
def pickleAsValue[T](value: T) = {
208208
value match {
209-
case null => ref(defn.QuotedExprModule).select("nullExpr".toTermName).appliedTo(qctx)
210-
case _: Unit => ref(defn.QuotedExprModule).select("unitExpr".toTermName).appliedTo(qctx)
209+
case null => ref(defn.QuotedExprModule).select("nullExpr".toTermName)
210+
case _: Unit => ref(defn.QuotedExprModule).select("unitExpr".toTermName)
211211
case _: Boolean => liftedValue(value, "Liftable_Boolean_delegate".toTermName)
212212
case _: Byte => liftedValue(value, "Liftable_Byte_delegate".toTermName)
213213
case _: Short => liftedValue(value, "Liftable_Short_delegate".toTermName)
@@ -229,9 +229,7 @@ class ReifyQuotes extends MacroTransform {
229229
else defn.FunctionType(1, isContextual = true).appliedTo(defn.QuoteContextClass.typeRef, defn.QuotedExprClass.typeRef.appliedTo(defn.AnyType)) | defn.QuotedTypeClass.typeRef.appliedTo(WildcardType)
230230
val pickledQuoteStrings = liftList(PickledQuotes.pickleQuote(body).map(x => Literal(Constant(x))), defn.StringType)
231231
val splicesList = liftList(splices, defn.FunctionType(1).appliedTo(defn.SeqType.appliedTo(defn.AnyType), spliceResType))
232-
val pickled = meth.appliedTo(pickledQuoteStrings, splicesList)
233-
if (isType) pickled
234-
else pickled.appliedTo(qctx)
232+
meth.appliedTo(pickledQuoteStrings, splicesList)
235233
}
236234

237235
if (splices.nonEmpty) pickleAsTasty()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object Splicer {
3636
* See: `Staging`
3737
*/
3838
def splice(tree: Tree, pos: SourcePosition, classLoader: ClassLoader)(implicit ctx: Context): Tree = tree match {
39-
case Quoted(quotedTree, _) => quotedTree
39+
case Quoted(quotedTree) => quotedTree
4040
case _ =>
4141
val interpreter = new Interpreter(pos, classLoader)
4242
try {
@@ -66,7 +66,7 @@ object Splicer {
6666
* See: `Staging`
6767
*/
6868
def checkValidMacroBody(tree: Tree)(implicit ctx: Context): Unit = tree match {
69-
case Quoted(_, _) => // ok
69+
case Quoted(_) => // ok
7070
case _ =>
7171
type Env = Set[Symbol]
7272

@@ -85,7 +85,7 @@ object Splicer {
8585
case Block(Nil, expr) => checkIfValidArgument(expr)
8686
case Typed(expr, _) => checkIfValidArgument(expr)
8787

88-
case Apply(Apply(TypeApply(fn, _), quoted :: Nil), qctx :: Nil) if fn.symbol == defn.InternalQuoted_exprQuote =>
88+
case Apply(Select(Apply(fn, quoted :: Nil), nme.apply), _) if fn.symbol == defn.InternalQuoted_exprQuote =>
8989
// OK
9090

9191
case TypeApply(fn, quoted :: Nil) if fn.symbol == defn.InternalQuoted_typeQuote =>
@@ -173,7 +173,7 @@ object Splicer {
173173

174174
def interpretTree(tree: Tree)(implicit env: Env): Object = {
175175
tree match {
176-
case Apply(Apply(TypeApply(fn, _), quoted :: Nil), qctx :: _) if fn.symbol == defn.InternalQuoted_exprQuote =>
176+
case Apply(Select(Apply(TypeApply(fn, _), quoted :: Nil), nme.apply), _) if fn.symbol == defn.InternalQuoted_exprQuote =>
177177
val quoted1 = quoted match {
178178
case quoted: Ident if quoted.symbol.isAllOf(InlineByNameProxy) =>
179179
// inline proxy for by-name parameter

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
5959
}
6060

6161
/** Transform the quote `quote` which contains the quoted `body`. */
62-
protected def transformQuotation(body: Tree, qctx: Tree, quote: Tree)(implicit ctx: Context): Tree = {
62+
protected def transformQuotation(body: Tree, quote: Tree)(implicit ctx: Context): Tree = {
6363
quote match {
64-
case Apply(t @ Apply(fun, _), _) => cpy.Apply(quote)(cpy.Apply(t)(fun, body :: Nil), qctx :: Nil)
64+
case quote: Apply => cpy.Apply(quote)(quote.fun, body :: Nil)
6565
case quote: TypeApply => cpy.TypeApply(quote)(quote.fun, body :: Nil)
6666
}
6767
}
@@ -88,18 +88,15 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
8888

8989
tree match {
9090

91-
case Quoted(quotedTree, qctx) =>
91+
case Quoted(quotedTree) =>
9292
dropEmptyBlocks(quotedTree) match {
93-
case SplicedExpr(t) =>
94-
// TODO beta-reduce
95-
transform(t).select(nme.apply).appliedTo(qctx) // '{ $x } --> x
96-
case SplicedType(t) => transform(t) // '[ $x ] --> x
97-
case _ => transformQuotation(quotedTree, qctx, tree)
93+
case Spliced(t) => transform(t) // '{ $x } --> x
94+
case _ => transformQuotation(quotedTree, tree)
9895
}
9996

10097
case tree @ Spliced(splicedTree) =>
10198
dropEmptyBlocks(splicedTree) match {
102-
case Quoted(t, _) => transform(t) // ${ 'x } --> x
99+
case Quoted(t) => transform(t) // ${ 'x } --> x
103100
case _ => transformSplice(splicedTree, tree)
104101
}
105102

@@ -113,9 +110,7 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
113110
// mark all bindings
114111
new TreeTraverser {
115112
def traverse(tree: Tree)(implicit ctx: Context): Unit = tree match {
116-
case Quoted(t, qctx) =>
117-
traverse(t)(quoteContext)
118-
traverse(qctx)
113+
case Quoted(t) => traverse(t)(quoteContext)
119114
case Splice(t) => traverse(t)(spliceContext)
120115
case _ =>
121116
markDef(tree)

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ trait QuotesAndSplices { self: Typer =>
3535
* while tracking the quotation level in the context.
3636
*/
3737
def typedQuote(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = track("typedQuote") {
38-
val qctx = inferImplicitArg(defn.QuoteContextClass.typeRef, tree.span)
39-
if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType])
40-
ctx.error(missingArgMsg(qctx, defn.QuoteContextClass.typeRef, ""), ctx.source.atSpan(tree.span))
41-
4238
tree.quoted match {
4339
case untpd.Splice(innerExpr) if tree.isTerm =>
4440
ctx.warning("Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ.", tree.sourcePos)
@@ -49,7 +45,7 @@ trait QuotesAndSplices { self: Typer =>
4945
ctx.compilationUnit.needsStaging = true
5046
val tree1 =
5147
if (tree.quoted.isType) typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuote.termRef), tree.quoted :: Nil), pt)(quoteContext)
52-
else if (ctx.mode.is(Mode.Pattern) && level == 0) typedQuotePattern(tree.quoted, pt, qctx)
48+
else if (ctx.mode.is(Mode.Pattern) && level == 0) typedQuotePattern(tree, pt)
5349
else typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuote.termRef), tree.quoted), pt)(quoteContext)
5450
tree1.withSpan(tree.span)
5551
}
@@ -296,7 +292,12 @@ trait QuotesAndSplices { self: Typer =>
296292
* ) => ...
297293
* ```
298294
*/
299-
private def typedQuotePattern(quoted: untpd.Tree, pt: Type, qctx: tpd.Tree)(implicit ctx: Context): Tree = {
295+
private def typedQuotePattern(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = {
296+
val qctx = inferImplicitArg(defn.QuoteContextClass.typeRef, tree.span)
297+
if (level == 0 && qctx.tpe.isInstanceOf[SearchFailureType])
298+
ctx.error(missingArgMsg(qctx, defn.QuoteContextClass.typeRef, ""), ctx.source.atSpan(tree.span))
299+
300+
val quoted = tree.quoted
300301
val exprPt = pt.baseType(defn.QuotedExprClass)
301302
val quotedPt = exprPt.argInfos.headOption match {
302303
case Some(argPt: ValueType) => argPt // excludes TypeBounds
@@ -347,7 +348,7 @@ trait QuotesAndSplices { self: Typer =>
347348
UnApply(
348349
fun = ref(defn.InternalQuotedMatcher_unapply.termRef).appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
349350
implicits =
350-
ref(defn.InternalQuoted_exprQuote.termRef).appliedToType(shape.tpe).appliedTo(shape).appliedTo(qctx) ::
351+
ref(defn.InternalQuoted_exprQuote.termRef).appliedToType(defn.AnyType).appliedTo(shape).select(nme.apply).appliedTo(qctx) ::
351352
Literal(Constant(typeBindings.nonEmpty)) ::
352353
qctx :: Nil,
353354
patterns = splicePat :: Nil,

library/src/scala/internal/Quoted.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Quoted {
77

88
/** A term quote is desugared by the compiler into a call to this method */
99
@compileTimeOnly("Illegal reference to `scala.internal.Quoted.exprQuote`")
10-
def exprQuote[T](x: T) given QuoteContext: Expr[T] = ???
10+
def exprQuote[T](x: T): given QuoteContext => Expr[T] = ???
1111

1212
/** A term splice is desugared by the compiler into a call to this method */
1313
@compileTimeOnly("Illegal reference to `scala.internal.Quoted.exprSplice`")

library/src/scala/quoted/Expr.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ package quoted {
4848
}
4949

5050
/** Returns a null expresssion equivalent to `'{null}` */
51-
def nullExpr given (qctx: QuoteContext): Expr[Null] = {
51+
def nullExpr: given QuoteContext => Expr[Null] = given qctx => {
5252
import qctx.tasty._
5353
Literal(Constant(null)).seal.asInstanceOf[Expr[Null]]
5454
}
5555

5656
/** Returns a unit expresssion equivalent to `'{}` or `'{()}` */
57-
def unitExpr given (qctx: QuoteContext): Expr[Unit] = {
57+
def unitExpr: given QuoteContext => Expr[Unit] = given qctx => {
5858
import qctx.tasty._
5959
Literal(Constant(())).seal.asInstanceOf[Expr[Unit]]
6060
}

library/src/scala/quoted/Liftable.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package scala.quoted
66
trait Liftable[T] {
77

88
/** Lift a value into an expression containing the construction of that value */
9-
def toExpr(x: T) given QuoteContext: Expr[T]
9+
def toExpr(x: T): given QuoteContext => Expr[T]
1010

1111
}
1212

@@ -29,15 +29,15 @@ object Liftable {
2929

3030
private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] {
3131
/** Lift a primitive value `n` into `'{ n }` */
32-
def toExpr(x: T) given (qctx: QuoteContext): Expr[T] = {
32+
def toExpr(x: T) = given qctx => {
3333
import qctx.tasty._
3434
Literal(Constant(x)).seal.asInstanceOf[Expr[T]]
3535
}
3636
}
3737

3838
implicit def ClassIsLiftable[T]: Liftable[Class[T]] = new Liftable[Class[T]] {
3939
/** Lift a `Class[T]` into `'{ classOf[T] }` */
40-
def toExpr(x: Class[T]) given (qctx: QuoteContext): Expr[Class[T]] = {
40+
def toExpr(x: Class[T]) = given qctx => {
4141
import qctx.tasty._
4242
Ref(definitions.Predef_classOf).appliedToType(Type(x)).seal.asInstanceOf[Expr[Class[T]]]
4343
}

library/src/scala/runtime/quoted/Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Unpickler {
1414
/** Unpickle `repr` which represents a pickled `Expr` tree,
1515
* replacing splice nodes with `args`
1616
*/
17-
def unpickleExpr[T](repr: Pickled, args: Seq[Seq[Any] => ((given QuoteContext => Expr[Any]) | Type[_])]) given QuoteContext: Expr[T] = new TastyExpr[T](repr, args)
17+
def unpickleExpr[T](repr: Pickled, args: Seq[Seq[Any] => ((given QuoteContext => Expr[Any]) | Type[_])]): given QuoteContext => Expr[T] = new TastyExpr[T](repr, args)
1818

1919
/** Unpickle `repr` which represents a pickled `Type` tree,
2020
* replacing splice nodes with `args`

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ trait Printers
806806
this += "throw "
807807
printTree(expr)
808808

809-
case Apply(Apply(fn, args), _) if fn.symbol.fullName == "scala.internal.Quoted$.exprQuote" =>
809+
case Apply(fn, args) if fn.symbol.fullName == "scala.internal.Quoted$.exprQuote" =>
810810
args.head match {
811811
case Block(stats, expr) =>
812812
this += "'{"
@@ -834,6 +834,8 @@ trait Printers
834834
case Apply(fn, args) =>
835835
fn match {
836836
case Select(This(_), "<init>") => this += "this" // call to constructor inside a constructor
837+
case Select(qual, "apply") if qual.tpe.classSymbol.exists(_.name.startsWith("ImplicitFunction")) =>
838+
printTree(qual) += " given "
837839
case _ => printQualTree(fn)
838840
}
839841
val args1 = args match {

tests/pos/quote-liftable-list-2.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import scala.quoted._
33
object Test {
44

55
implicit def ListIsLiftableOr[T: Type, U: Type]: Liftable[List[T | U]] = new {
6-
def toExpr(xs: List[T | U]) given QuoteContext: Expr[List[T | U]] = '{ Nil: List[T | U] }
7-
}
8-
9-
implicit def ListIsLiftableAnd[T: Type, U: Type]: Liftable[List[T & U]] = new {
10-
def toExpr(xs: List[T & U]) given QuoteContext: Expr[List[T & U]] = '{ Nil: List[T & U] }
6+
def toExpr(xs: List[T | U]): given QuoteContext => Expr[List[T | U]] = '{ Nil: List[T | U] }
117
}
128

139
}

tests/pos/quote-liftable-list-3.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted._
2+
3+
object Test {
4+
5+
implicit def ListIsLiftableAnd[T: Type, U: Type]: Liftable[List[T & U]] = new {
6+
def toExpr(xs: List[T & U]): given QuoteContext => Expr[List[T & U]] = '{ Nil: List[T & U] }
7+
}
8+
9+
}

tests/pos/quote-liftable-list.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.quoted._
33
object Test {
44

55
implicit def ListIsLiftable[T: Liftable: Type]: Liftable[List[T]] = new {
6-
def toExpr(xs: List[T]) given QuoteContext: Expr[List[T]] = '{ Nil: List[T] }
6+
def toExpr(xs: List[T]) = '{ Nil: List[T] }
77
}
88

99
}

tests/pos/quote-liftable.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def test given QuoteContext = {
55
delegate for QuoteContext = ???
66

77
implicit def IntIsLiftable: Liftable[Int] = new {
8-
def toExpr(n: Int) given QuoteContext: Expr[Int] = n match {
8+
def toExpr(n: Int) = n match {
99
case Int.MinValue => '{Int.MinValue}
1010
case _ if n < 0 => '{- ${toExpr(n)}}
1111
case 0 => '{0}
@@ -15,12 +15,12 @@ def test given QuoteContext = {
1515
}
1616

1717
implicit def BooleanIsLiftable: Liftable[Boolean] = new {
18-
implicit def toExpr(b: Boolean) given QuoteContext: Expr[Boolean] =
18+
implicit def toExpr(b: Boolean) =
1919
if (b) '{true} else '{false}
2020
}
2121

2222
implicit def ListIsLiftable[T: Liftable: Type]: Liftable[List[T]] = new {
23-
def toExpr(xs: List[T]) given QuoteContext: Expr[List[T]] = xs match {
23+
def toExpr(xs: List[T]) = xs match {
2424
case x :: xs1 => '{ ${ implicitly[Liftable[T]].toExpr(x) } :: ${ toExpr(xs1) } }
2525
case Nil => '{Nil: List[T]}
2626
}

0 commit comments

Comments
 (0)