diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index 5f1c769ccb6a..62956dde81c6 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -112,6 +112,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( if (tp.isTerm) ctx.error(i"splice outside quotes", pos) tp + case tp: TypeRef if tp.symbol == defn.QuotedTypeClass.typeParams.head => + // Adapt direct references to the type of the type parameter T of a quoted.Type[T]. + // Replace it with a properly encoded type splice. This is the normal for expected for type splices. + tp.prefix.select(tpnme.splice) case tp: NamedType => checkSymLevel(tp.symbol, tp, pos) match { case Some(tpRef) => tpRef.tpe diff --git a/tests/pos/i6997.scala b/tests/pos/i6997.scala new file mode 100644 index 000000000000..2ac86b1def07 --- /dev/null +++ b/tests/pos/i6997.scala @@ -0,0 +1,8 @@ + +import scala.quoted._ +class Foo { + def mcrImpl(body: Expr[Any]) given (t: Type[_ <: Any]) given (ctx: QuoteContext): Expr[Any] = '{ + val tmp = ???.asInstanceOf[$t] + tmp + } +} diff --git a/tests/pos/i6997b.scala b/tests/pos/i6997b.scala new file mode 100644 index 000000000000..7b49aef3b2a4 --- /dev/null +++ b/tests/pos/i6997b.scala @@ -0,0 +1,15 @@ +package playground + +import scala.quoted._, scala.quoted.matching._ +import delegate scala.quoted._ + +inline def mcr(x: => Any): Any = ${mcrImpl('x)} + +def mcrImpl(body: Expr[Any]) given (ctx: QuoteContext): Expr[Any] = { + val '{$x: $t} = body + '{ + val tmp: $t = $x.asInstanceOf[$t] + println(tmp) + tmp + } +} \ No newline at end of file