Skip to content

Commit 6e20e72

Browse files
committed
Fix #6997: Adapt quote type direct aliase to type splice
1 parent de43ee1 commit 6e20e72

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
112112
if (tp.isTerm)
113113
ctx.error(i"splice outside quotes", pos)
114114
tp
115+
case tp: TypeRef if tp.prefix.derivesFrom(defn.QuotedTypeClass) && tp.name.toString == "T" =>
116+
// Adapt direct references to the type of the type parameter T of a quoted.Type[T].
117+
// Replace it with a properly encoded type splice. This is the normal for expected for type splices.
118+
tp.prefix.select(tpnme.splice)
115119
case tp: NamedType =>
116120
checkSymLevel(tp.symbol, tp, pos) match {
117121
case Some(tpRef) => tpRef.tpe

tests/pos/i6997.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
import scala.quoted._
3+
class Foo {
4+
def mcrImpl(body: Expr[Any]) given (t: Type[_ <: Any]) given (ctx: QuoteContext): Expr[Any] = '{
5+
val tmp = ???.asInstanceOf[$t]
6+
tmp
7+
}
8+
}

tests/pos/i6997b.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package playground
2+
3+
import scala.quoted._, scala.quoted.matching._
4+
import delegate scala.quoted._
5+
6+
inline def mcr(x: => Any): Any = ${mcrImpl('x)}
7+
8+
def mcrImpl(body: Expr[Any]) given (ctx: QuoteContext): Expr[Any] = {
9+
val '{$x: $t} = body
10+
'{
11+
val tmp: $t = $x.asInstanceOf[$t]
12+
println(tmp)
13+
tmp
14+
}
15+
}

0 commit comments

Comments
 (0)