Skip to content

Commit af669fd

Browse files
committed
Fix quoted path dependent types
Fixes #8100 Fixes #12440
1 parent 4bf2f04 commit af669fd

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
6666
checkAnnotations(tree)
6767
super.transform(tree)
6868
else tree match {
69-
70-
case _: TypeTree | _: RefTree if tree.isType =>
69+
case tree: TypeTree =>
70+
val tree1 = treeify(tree)
71+
if tree ne tree1 then transform(tree1.withSpan(tree.span))
72+
else
73+
val healedType = healType(tree.srcPos)(tree.tpe)
74+
if healedType == tree.tpe then tree
75+
else TypeTree(healedType).withSpan(tree.span)
76+
case _: RefTree if tree.isType =>
7177
val healedType = healType(tree.srcPos)(tree.tpe)
7278
if healedType == tree.tpe then tree
7379
else TypeTree(healedType).withSpan(tree.span)
@@ -275,6 +281,18 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
275281
tp
276282
}
277283

284+
/** Transform a TypeTree into a tree that contains the structure of the type */
285+
private def treeify(tree: TypeTree)(using Context): Tree =
286+
tree.tpe.stripTypeVar.dealias match
287+
case tpe @ TypeRef(path: TermRef, _) =>
288+
// Expand TypeTree(`x.T`) to Select(`x`, `T`)
289+
// Needed in PickleQuotes in case x refers to a captured reference.
290+
ref(path).select(tpe)
291+
case AppliedType(tycon, args) =>
292+
AppliedTypeTree(treeify(TypeTree(tycon)), args.map(TypeTree))
293+
case _ =>
294+
tree
295+
278296
}
279297

280298
object PCPCheckAndHeal {

tests/pos-macros/i12440.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import scala.quoted.*
2+
3+
trait Mirror:
4+
type ElemTypes <: Tuple
5+
6+
class Eq:
7+
8+
def test1(using Quotes): Unit = '{
9+
val m: Mirror = ???
10+
${ summonType[m.ElemTypes]; ??? }
11+
${ summonType[List[m.ElemTypes]]; ??? }
12+
}
13+
14+
def test2(using Quotes): Unit = '{
15+
val m: Mirror = ???
16+
type ET = m.ElemTypes
17+
${ summonType[ET]; ??? }
18+
${ summonType[List[ET]]; ??? }
19+
}
20+
21+
def summonType[X](using Type[X]) = ???

tests/pos-macros/i8100.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def f[T: Type](using Quotes) =
1414
${ g[m.E](using Type.of[ME]) }
1515
${ g[ME](using Type.of[m.E]) }
1616
${ g[m.E](using Type.of[m.E]) }
17-
// ${ g[ME] } // FIXME: issue seems to be in PickleQuotes
18-
// ${ g[m.E] } // FIXME: issue seems to be in PickleQuotes
17+
${ g[ME] }
18+
${ g[m.E] }
1919
}
2020

21-
def g[T](using Type[T]) = ???
21+
def g[T](using Type[T]) = ???

0 commit comments

Comments
 (0)