Skip to content

Commit 1159170

Browse files
committed
Heal type within quote internal encoding
Fixes scala#11587
1 parent 0be4099 commit 1159170

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,19 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
118118
case Nil => body1
119119
case tags => tpd.Block(tags, body1).withSpan(body.span)
120120

121-
super.transformQuotation(body2, quote)
121+
quote match {
122+
case Apply(fn1 @ TypeApply(fn0, targs), _) =>
123+
val heal = new TypeMap {
124+
def apply(tp: Type) = tp match {
125+
case AnnotatedType(parent, annot) => AnnotatedType(mapOver(parent), annot)
126+
case _ => healTypeOfTerm(fn1.srcPos)(tp)
127+
}
128+
}
129+
val targs1 = targs.map(targ => TypeTree(heal(targ.tpe)))
130+
cpy.Apply(quote)(cpy.TypeApply(fn1)(fn0, targs1), body2 :: Nil)
131+
case quote: TypeApply =>
132+
cpy.TypeApply(quote)(quote.fun, body2 :: Nil)
133+
}
122134
}
123135

124136
/** Transform splice

tests/pos-macros/i11587.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted._
2+
class Foo:
3+
def foo[T: Type](using Quotes): Unit = '{ // level 1
4+
given Quotes = ???
5+
6+
Type.of[T]
7+
8+
'{ ??? : T } // level 2
9+
10+
'{ // level 2
11+
given Quotes = ???
12+
Type.of[T]
13+
'{ ??? : T } // level 3
14+
}
15+
}

0 commit comments

Comments
 (0)