Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scala.quoted.Liftables to the stdlib #6928

Merged
merged 10 commits into from
Jul 26, 2019
9 changes: 9 additions & 0 deletions library/src-non-bootstrapped/scala/quoted/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ package object quoted {
def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T =
throw new Exception("Non bootsrapped library")

implicit object ExprOps {
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)

def (seq: Seq[Expr[T]]) toExprOfSeq[T] given (tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] =
throw new Exception("Non bootsrapped library")

def (list: List[Expr[T]]) toExprOfList[T] given Type[T], QuoteContext: Expr[List[T]] =
throw new Exception("Non bootsrapped library")
}
}
189 changes: 189 additions & 0 deletions library/src/scala/quoted/Liftable.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package scala.quoted

import scala.reflect.ClassTag

/** A typeclass for types that can be turned to `quoted.Expr[T]`
* without going through an explicit `'{...}` operation.
*/
Expand Down Expand Up @@ -43,4 +45,191 @@ object Liftable {
}
}

given [T: Type: Liftable: ClassTag] as Liftable[IArray[T]] = new Liftable[IArray[T]] {
def toExpr(iarray: IArray[T]): given QuoteContext => Expr[IArray[T]] = '{
val array = new Array[T](${iarray.length.toExpr})(ClassTag(${the[ClassTag[T]].runtimeClass.toExpr}))
${ Expr.block(List.tabulate(iarray.length)(i => '{ array(${i.toExpr}) = ${iarray(i).toExpr} }), '{ array.asInstanceOf[IArray[T]] }) }
}
}

given [T: Type: Liftable] as Liftable[Seq[T]] = new Liftable[Seq[T]] {
def toExpr(xs: Seq[T]): given QuoteContext => Expr[Seq[T]] =
xs.map(the[Liftable[T]].toExpr).toExprOfSeq
}

given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] {
def toExpr(xs: List[T]): given QuoteContext => Expr[List[T]] =
xs.map(the[Liftable[T]].toExpr).toExprOfList
}
nicolasstucki marked this conversation as resolved.
Show resolved Hide resolved

given [T: Type: Liftable] as Liftable[Set[T]] = new Liftable[Set[T]] {
def toExpr(set: Set[T]): given QuoteContext => Expr[Set[T]] =
'{ Set(${set.toSeq.toExpr}: _*) }
}

given [T: Type: Liftable, U: Type: Liftable] as Liftable[Map[T, U]] = new Liftable[Map[T, U]] {
def toExpr(map: Map[T, U]): given QuoteContext => Expr[Map[T, U]] =
'{ Map(${map.toSeq.toExpr}: _*) }
}

given [T: Type: Liftable] as Liftable[Option[T]] = new Liftable[Option[T]] {
def toExpr(x: Option[T]): given QuoteContext => Expr[Option[T]] = x match {
case Some(x) => '{ Some[T](${x.toExpr}) }
case None => '{ None: Option[T] }
}
}

given [L: Type: Liftable, R: Type: Liftable] as Liftable[Either[L, R]] = new Liftable[Either[L, R]] {
def toExpr(x: Either[L, R]): given QuoteContext => Expr[Either[L, R]] = x match {
case Left(x) => '{ Left[L, R](${x.toExpr}) }
case Right(x) => '{ Right[L, R](${x.toExpr}) }
}
}

given [T1: Type: Liftable] as Liftable[Tuple1[T1]] = new {
def toExpr(tup: Tuple1[T1]) =
'{ Tuple1(${tup._1.toExpr}) }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: maybe still write new Liftable[...] to be consistent and explicit as above, the same for the code below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It got way too long and made it harder to read.


given [T1: Type: Liftable, T2: Type: Liftable] as Liftable[Tuple2[T1, T2]] = new {
def toExpr(tup: Tuple2[T1, T2]) =
'{ (${tup._1.toExpr}, ${tup._2.toExpr}) }
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable] as Liftable[Tuple3[T1, T2, T3]] = new {
def toExpr(tup: Tuple3[T1, T2, T3]) =
'{ (${tup._1.toExpr}, ${tup._2.toExpr}, ${tup._3.toExpr}) }
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable] as Liftable[Tuple4[T1, T2, T3, T4]] = new {
def toExpr(tup: Tuple4[T1, T2, T3, T4]) =
'{ (${tup._1.toExpr}, ${tup._2.toExpr}, ${tup._3.toExpr}, ${tup._4.toExpr}) }
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable] as Liftable[Tuple5[T1, T2, T3, T4, T5]] = new {
def toExpr(tup: Tuple5[T1, T2, T3, T4, T5]) = {
val (x1, x2, x3, x4, x5) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable] as Liftable[Tuple6[T1, T2, T3, T4, T5, T6]] = new {
def toExpr(tup: Tuple6[T1, T2, T3, T4, T5, T6]) = {
val (x1, x2, x3, x4, x5, x6) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable] as Liftable[Tuple7[T1, T2, T3, T4, T5, T6, T7]] = new {
def toExpr(tup: Tuple7[T1, T2, T3, T4, T5, T6, T7]) = {
val (x1, x2, x3, x4, x5, x6, x7) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable] as Liftable[Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] = new {
def toExpr(tup: Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable] as Liftable[Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] = new {
def toExpr(tup: Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable] as Liftable[Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] = new {
def toExpr(tup: Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable] as Liftable[Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]] = new {
def toExpr(tup: Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable] as Liftable[Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]] = new {
def toExpr(tup: Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable] as Liftable[Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]] = new {
def toExpr(tup: Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable] as Liftable[Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]] = new {
def toExpr(tup: Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable] as Liftable[Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]] = new {
def toExpr(tup: Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable] as Liftable[Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]] = new {
def toExpr(tup: Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable] as Liftable[Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]] = new {
def toExpr(tup: Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable] as Liftable[Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]] = new {
def toExpr(tup: Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable, T19: Type: Liftable] as Liftable[Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]] = new {
def toExpr(tup: Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}, ${x19.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable, T19: Type: Liftable, T20: Type: Liftable] as Liftable[Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]] = new {
def toExpr(tup: Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}, ${x19.toExpr}, ${x20.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable, T19: Type: Liftable, T20: Type: Liftable, T21: Type: Liftable] as Liftable[Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]] = new {
def toExpr(tup: Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}, ${x19.toExpr}, ${x20.toExpr}, ${x21.toExpr}) }
}
}

given [T1: Type: Liftable, T2: Type: Liftable, T3: Type: Liftable, T4: Type: Liftable, T5: Type: Liftable, T6: Type: Liftable, T7: Type: Liftable, T8: Type: Liftable, T9: Type: Liftable, T10: Type: Liftable, T11: Type: Liftable, T12: Type: Liftable, T13: Type: Liftable, T14: Type: Liftable, T15: Type: Liftable, T16: Type: Liftable, T17: Type: Liftable, T18: Type: Liftable, T19: Type: Liftable, T20: Type: Liftable, T21: Type: Liftable, T22: Type: Liftable] as Liftable[Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]] = new {
def toExpr(tup: Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]) = {
val (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22) = tup
'{ (${x1.toExpr}, ${x2.toExpr}, ${x3.toExpr}, ${x4.toExpr}, ${x5.toExpr}, ${x6.toExpr}, ${x7.toExpr}, ${x8.toExpr}, ${x9.toExpr}, ${x10.toExpr}, ${x11.toExpr}, ${x12.toExpr}, ${x13.toExpr}, ${x14.toExpr}, ${x15.toExpr}, ${x16.toExpr}, ${x17.toExpr}, ${x18.toExpr}, ${x19.toExpr}, ${x20.toExpr}, ${x21.toExpr}, ${x22.toExpr}) }
}
}

}
7 changes: 0 additions & 7 deletions tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,4 @@ object TypeToolbox {
companionClassOpt.map(_.fullName).getOrElse("").toExpr
}

// TODO add to the std lib
private implicit def listIsLiftable[T: Type: Liftable]: Liftable[List[T]] = new Liftable {
def toExpr(list: List[T]) = list match {
case x :: xs => '{${x.toExpr} :: ${toExpr(xs)}}
case Nil => '{Nil}
}
}
}
6 changes: 0 additions & 6 deletions tests/run-macros/quote-force/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,4 @@ object Location {
'{new Location(${list})}
}

private implicit def ListIsLiftable[T : Liftable : Type]: Liftable[List[T]] = new Liftable[List[T]] {
def toExpr(x: List[T]) = x match {
case x :: xs => '{ ${x} :: ${xs} }
case Nil => '{ List.empty[T] }
}
}
}
11 changes: 1 addition & 10 deletions tests/run-macros/tasty-interpolation-1/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,7 @@ abstract class MacroStringInterpolator[T] {
}

protected implicit def StringContextIsLiftable: Liftable[StringContext] = new Liftable[StringContext] {
def toExpr(strCtx: StringContext) = {
// TODO define in stdlib?
implicit def ListIsLiftable: Liftable[List[String]] = new Liftable[List[String]] {
override def toExpr(list: List[String]) = list match {
case x :: xs => '{${x.toExpr} :: ${toExpr(xs)}}
case Nil => '{Nil}
}
}
'{StringContext(${strCtx.parts.toList}: _*)}
}
def toExpr(strCtx: StringContext) = '{StringContext(${strCtx.parts.toList}: _*)}
}

protected class NotStaticlyKnownError(msg: String, expr: Expr[Any]) extends Exception(msg)
Expand Down
6 changes: 0 additions & 6 deletions tests/run-macros/tasty-location/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,4 @@ object Location {
'{new Location(${list})}
}

private implicit def ListIsLiftable[T : Liftable : Type]: Liftable[List[T]] = new Liftable[List[T]] {
def toExpr(x: List[T]) = x match {
case x :: xs => '{ $x :: $xs }
case Nil => '{ List.empty[T] }
}
}
}
Loading