Skip to content

Fix #7046: Support lifting for literal constant types #7055

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

Merged
merged 3 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ class ReifyQuotes extends MacroTransform {
}

def liftedValue[T](value: T, name: TermName) =
ref(defn.LiftableModule).select(name).select("toExpr".toTermName).appliedTo(Literal(Constant(value)))
ref(defn.LiftableModule)
.select(name).appliedToType(originalTp)
.select("toExpr".toTermName).appliedTo(Literal(Constant(value)))

def pickleAsValue[T](value: T) = {
value match {
Expand Down
18 changes: 9 additions & 9 deletions library/src-bootstrapped/scala/quoted/Liftable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ trait Liftable[T] {
*/
object Liftable {

given Liftable_Boolean_delegate as Liftable[Boolean] = new PrimitiveLiftable
given Liftable_Byte_delegate as Liftable[Byte] = new PrimitiveLiftable
given Liftable_Short_delegate as Liftable[Short] = new PrimitiveLiftable
given Liftable_Int_delegate as Liftable[Int] = new PrimitiveLiftable
given Liftable_Long_delegate as Liftable[Long] = new PrimitiveLiftable
given Liftable_Float_delegate as Liftable[Float] = new PrimitiveLiftable
given Liftable_Double_delegate as Liftable[Double] = new PrimitiveLiftable
given Liftable_Char_delegate as Liftable[Char] = new PrimitiveLiftable
given Liftable_String_delegate as Liftable[String] = new PrimitiveLiftable
given Liftable_Boolean_delegate[T <: Boolean] as Liftable[T] = new PrimitiveLiftable
given Liftable_Byte_delegate[T <: Byte] as Liftable[T] = new PrimitiveLiftable
given Liftable_Short_delegate[T <: Short] as Liftable[T] = new PrimitiveLiftable
given Liftable_Int_delegate[T <: Int] as Liftable[T] = new PrimitiveLiftable
given Liftable_Long_delegate[T <: Long] as Liftable[T] = new PrimitiveLiftable
given Liftable_Float_delegate[T <: Float] as Liftable[T] = new PrimitiveLiftable
given Liftable_Double_delegate[T <: Double] as Liftable[T] = new PrimitiveLiftable
given Liftable_Char_delegate[T <: Char] as Liftable[T] = new PrimitiveLiftable
given Liftable_String_delegate[T <: String] as Liftable[T] = new PrimitiveLiftable

private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] {
/** Lift a primitive value `n` into `'{ n }` */
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i7046.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted._

inline def mcr: Any = ${mcrImpl}
def mcrImpl given (ctx: QuoteContext): Expr[Any] = {
val tpl: Expr[1] = '{1}
'{()}
}