File tree 3 files changed +27
-0
lines changed
compiler/src/dotty/tools/dotc/transform 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
112
112
if (tp.isTerm)
113
113
ctx.error(i " splice outside quotes " , pos)
114
114
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)
115
119
case tp : NamedType =>
116
120
checkSymLevel(tp.symbol, tp, pos) match {
117
121
case Some (tpRef) => tpRef.tpe
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments