Skip to content

Commit a6048a7

Browse files
committed
Add quoted.Liftable[Option[T]] to the stdlib
1 parent b334a94 commit a6048a7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

library/src/scala/quoted/Liftable.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ object Liftable {
5959
}
6060
}
6161

62+
given [T: Type: Liftable] as Liftable[Option[T]] = new Liftable[Option[T]] {
63+
def toExpr(x: Option[T]): given QuoteContext => Expr[Option[T]] = x match {
64+
case Some(x) => '{ Some[T](${x.toExpr}) }
65+
case None => '{ None: Option[T] }
66+
}
67+
}
68+
6269
}

tests/run-with-compiler/quote-lib.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ object Test {
3838
val iarray: IArray[Int] = IArray(1, 2, 3)
3939
val liftedIArray: Expr[IArray[Int]] = iarray
4040

41+
val some: Option[Int] = Some(2)
42+
val none: Option[Int] = Some(2)
43+
val liftedSome: Expr[Option[Int]] = some
44+
val liftedNone: Expr[Option[Int]] = none
45+
4146
println("quote lib ok")
4247
}
4348
}

0 commit comments

Comments
 (0)