Skip to content

Commit 7d39f0e

Browse files
committed
Simplify avoidance of local types of Hole
1 parent ca7c29f commit 7d39f0e

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

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

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class PickleQuotes extends MacroTransform {
112112
assert(isTerm)
113113
assert(!content.isEmpty)
114114
holeContents += content
115-
val holeType = getTermHoleType(tree.tpe)
115+
val holeType = avoidNonStaticTypes(tree.tpe)
116116
val hole = untpd.cpy.Hole(tree)(content = EmptyTree).withType(holeType)
117117
cpy.Inlined(tree)(EmptyTree, Nil, hole)
118118
case tree: DefTree =>
@@ -134,19 +134,6 @@ class PickleQuotes extends MacroTransform {
134134
}
135135
}
136136

137-
/** Remove references to local types that will not be defined in this quote */
138-
private def getTermHoleType(using Context) = new TypeMap() {
139-
override def apply(tp: Type): Type = tp match
140-
case tp @ TypeRef(NoPrefix, _) =>
141-
// reference to term with a type defined in outer quote
142-
getTypeHoleType(tp)
143-
case tp @ TermRef(NoPrefix, _) =>
144-
// widen term refs to terms defined in outer quote
145-
apply(tp.widenTermRefExpr)
146-
case tp =>
147-
mapOver(tp)
148-
}
149-
150137
/** Get the holeContents of the transformed tree */
151138
def getContents() =
152139
val res = holeContents.result
@@ -196,11 +183,11 @@ class PickleQuotes extends MacroTransform {
196183
cpy.Quote(quote)(Block(tdefs, body1), quote.tags)
197184

198185
private def mkTagSymbolAndAssignType(typeArg: Tree, idx: Int)(using Context): TypeDef = {
199-
val holeType = getTypeHoleType(typeArg.tpe.select(tpnme.Underlying))
186+
val holeType = avoidNonStaticTypes(typeArg.tpe.select(tpnme.Underlying))
200187
val hole = untpd.cpy.Hole(typeArg)(isTerm = false, idx, Nil, EmptyTree).withType(holeType)
201188
val local = newSymbol(
202189
owner = ctx.owner,
203-
name = UniqueName.fresh(hole.tpe.dealias.typeSymbol.name.toTypeName),
190+
name = UniqueName.fresh(typeArg.symbol.name.toTypeName),
204191
flags = Synthetic,
205192
info = TypeAlias(typeArg.tpe.select(tpnme.Underlying)),
206193
coord = typeArg.span
@@ -209,25 +196,10 @@ class PickleQuotes extends MacroTransform {
209196
ctx.typeAssigner.assignType(untpd.TypeDef(local.name, hole), local).withSpan(typeArg.span)
210197
}
211198

212-
/** Remove references to local types that will not be defined in this quote */
213-
private def getTypeHoleType(using Context) = new TypeMap() {
214-
override def apply(tp: Type): Type = tp match
215-
case tp: TypeRef if tp.typeSymbol.isTypeSplice =>
216-
apply(tp.dealias)
217-
case tp @ TypeRef(pre, _) if isLocalPath(pre) =>
218-
val hiBound = tp.typeSymbol.info match
219-
case info: ClassInfo => info.parents.reduce(_ & _)
220-
case info => info.hiBound
221-
apply(hiBound)
222-
case tp =>
223-
mapOver(tp)
224-
225-
private def isLocalPath(tp: Type): Boolean = tp match
226-
case NoPrefix => true
227-
case tp: TermRef if !tp.symbol.is(Package) => isLocalPath(tp.prefix)
228-
case tp => false
229-
}
230-
199+
private def avoidNonStaticTypes(tpe: Type)(using Context) =
200+
new TypeOps.AvoidMap {
201+
def toAvoid(tp: NamedType) = !isStaticPrefix(tp)
202+
}.apply(tpe)
231203
}
232204

233205
object PickleQuotes {

0 commit comments

Comments
 (0)