Skip to content

Commit 78d92a4

Browse files
committed
Use AvoidMap to take bounds and variance into account
1 parent a135d9e commit 78d92a4

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import dotty.tools.dotc.config.ScalaRelease.*
1919
import scala.collection.mutable
2020
import dotty.tools.dotc.core.Annotations._
2121
import dotty.tools.dotc.core.StdNames._
22+
import dotty.tools.dotc.core.TypeOps.AvoidMap
2223
import dotty.tools.dotc.quoted._
2324
import dotty.tools.dotc.inlines.Inlines
2425

@@ -135,16 +136,9 @@ class PickleQuotes extends MacroTransform {
135136
}
136137

137138
/** 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)
139+
private def getTermHoleType(using Context) = new AvoidMap {
140+
def toAvoid(tp: NamedType): Boolean =
141+
tp.prefix == NoPrefix // reference to terms and type defined in outer quote
148142
}
149143

150144
/** Get the contents of the transformed tree */
@@ -210,24 +204,15 @@ class PickleQuotes extends MacroTransform {
210204
}
211205

212206
/** 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)
207+
private def getTypeHoleType(using Context) = new AvoidMap {
208+
def toAvoid(tp: NamedType): Boolean =
209+
tp.typeSymbol.isTypeSplice || isLocalPath(tp.prefix)
224210

225211
private def isLocalPath(tp: Type): Boolean = tp match
226212
case NoPrefix => true
227213
case tp: TermRef if !tp.symbol.is(Package) => isLocalPath(tp.prefix)
228214
case tp => false
229215
}
230-
231216
}
232217

233218
object PickleQuotes {

0 commit comments

Comments
 (0)