Skip to content

Fix inferred quoted path dependent types #12443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
checkAnnotations(tree)
super.transform(tree)
else tree match {

case _: TypeTree | _: RefTree if tree.isType =>
case tree: TypeTree =>
val tree1 = treeify(tree)
if tree ne tree1 then transform(tree1.withSpan(tree.span))
else
val healedType = healType(tree.srcPos)(tree.tpe)
if healedType == tree.tpe then tree
else TypeTree(healedType).withSpan(tree.span)
case _: RefTree if tree.isType =>
val healedType = healType(tree.srcPos)(tree.tpe)
if healedType == tree.tpe then tree
else TypeTree(healedType).withSpan(tree.span)
Expand Down Expand Up @@ -275,6 +281,18 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
tp
}

/** Transform a TypeTree into a tree that contains the structure of the type */
private def treeify(tree: TypeTree)(using Context): Tree =
tree.tpe.stripTypeVar.dealias match
case tpe @ TypeRef(path: TermRef, _) =>
// Expand TypeTree(`x.T`) to Select(`x`, `T`)
// Needed in PickleQuotes in case x refers to a captured reference.
ref(path).select(tpe)
case AppliedType(tycon, args) =>
AppliedTypeTree(treeify(TypeTree(tycon)), args.map(TypeTree))
case _ =>
tree

}

object PCPCheckAndHeal {
Expand Down
21 changes: 21 additions & 0 deletions tests/pos-macros/i12440.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import scala.quoted.*

trait Mirror:
type ElemTypes <: Tuple

class Eq:

def test1(using Quotes): Unit = '{
val m: Mirror = ???
${ summonType[m.ElemTypes]; ??? }
${ summonType[List[m.ElemTypes]]; ??? }
}

def test2(using Quotes): Unit = '{
val m: Mirror = ???
type ET = m.ElemTypes
${ summonType[ET]; ??? }
${ summonType[List[ET]]; ??? }
}

def summonType[X](using Type[X]) = ???
6 changes: 3 additions & 3 deletions tests/pos-macros/i8100.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def f[T: Type](using Quotes) =
${ g[m.E](using Type.of[ME]) }
${ g[ME](using Type.of[m.E]) }
${ g[m.E](using Type.of[m.E]) }
// ${ g[ME] } // FIXME: issue seems to be in PickleQuotes
// ${ g[m.E] } // FIXME: issue seems to be in PickleQuotes
${ g[ME] }
${ g[m.E] }
}

def g[T](using Type[T]) = ???
def g[T](using Type[T]) = ???