Skip to content

Commit 2c12b93

Browse files
authored
Merge pull request #7055 from dotty-staging/i7046
Fix #7046: Support lifting for literal constant types
2 parents cea5a62 + 1c3029d commit 2c12b93

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ class ReifyQuotes extends MacroTransform {
209209
}
210210

211211
def liftedValue[T](value: T, name: TermName) =
212-
ref(defn.LiftableModule).select(name).select("toExpr".toTermName).appliedTo(Literal(Constant(value)))
212+
ref(defn.LiftableModule)
213+
.select(name).appliedToType(originalTp)
214+
.select("toExpr".toTermName).appliedTo(Literal(Constant(value)))
213215

214216
def pickleAsValue[T](value: T) = {
215217
value match {

library/src-bootstrapped/scala/quoted/Liftable.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ trait Liftable[T] {
1919
*/
2020
object Liftable {
2121

22-
given Liftable_Boolean_delegate as Liftable[Boolean] = new PrimitiveLiftable
23-
given Liftable_Byte_delegate as Liftable[Byte] = new PrimitiveLiftable
24-
given Liftable_Short_delegate as Liftable[Short] = new PrimitiveLiftable
25-
given Liftable_Int_delegate as Liftable[Int] = new PrimitiveLiftable
26-
given Liftable_Long_delegate as Liftable[Long] = new PrimitiveLiftable
27-
given Liftable_Float_delegate as Liftable[Float] = new PrimitiveLiftable
28-
given Liftable_Double_delegate as Liftable[Double] = new PrimitiveLiftable
29-
given Liftable_Char_delegate as Liftable[Char] = new PrimitiveLiftable
30-
given Liftable_String_delegate as Liftable[String] = new PrimitiveLiftable
22+
given Liftable_Boolean_delegate[T <: Boolean] as Liftable[T] = new PrimitiveLiftable
23+
given Liftable_Byte_delegate[T <: Byte] as Liftable[T] = new PrimitiveLiftable
24+
given Liftable_Short_delegate[T <: Short] as Liftable[T] = new PrimitiveLiftable
25+
given Liftable_Int_delegate[T <: Int] as Liftable[T] = new PrimitiveLiftable
26+
given Liftable_Long_delegate[T <: Long] as Liftable[T] = new PrimitiveLiftable
27+
given Liftable_Float_delegate[T <: Float] as Liftable[T] = new PrimitiveLiftable
28+
given Liftable_Double_delegate[T <: Double] as Liftable[T] = new PrimitiveLiftable
29+
given Liftable_Char_delegate[T <: Char] as Liftable[T] = new PrimitiveLiftable
30+
given Liftable_String_delegate[T <: String] as Liftable[T] = new PrimitiveLiftable
3131

3232
private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] {
3333
/** Lift a primitive value `n` into `'{ n }` */

tests/pos/i7046.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted._
2+
3+
inline def mcr: Any = ${mcrImpl}
4+
def mcrImpl given (ctx: QuoteContext): Expr[Any] = {
5+
val tpl: Expr[1] = '{1}
6+
'{()}
7+
}

0 commit comments

Comments
 (0)