@@ -2,7 +2,7 @@ package dotty.tools.dotc
22package staging
33
44import dotty .tools .dotc .ast .{tpd , untpd }
5- import dotty .tools .dotc .core .Annotations .BodyAnnotation
5+ import dotty .tools .dotc .core .Annotations ._
66import dotty .tools .dotc .core .Contexts ._
77import dotty .tools .dotc .core .Decorators ._
88import dotty .tools .dotc .core .Flags ._
@@ -11,15 +11,10 @@ import dotty.tools.dotc.core.StagingContext._
1111import dotty .tools .dotc .core .StdNames ._
1212import dotty .tools .dotc .core .Symbols ._
1313import dotty .tools .dotc .core .Types ._
14- import dotty .tools .dotc .util .SrcPos
15- import dotty .tools .dotc .util .Spans ._
16- import dotty .tools .dotc .transform .SymUtils ._
17- import dotty .tools .dotc .typer .Checking
18- import dotty .tools .dotc .typer .Implicits .SearchFailureType
19- import dotty .tools .dotc .core .Annotations ._
2014import dotty .tools .dotc .staging .StagingLevel .*
21-
2215import dotty .tools .dotc .util .Property
16+ import dotty .tools .dotc .util .Spans ._
17+ import dotty .tools .dotc .util .SrcPos
2318
2419/** Checks that the Phase Consistency Principle (PCP) holds and heals types.
2520 *
@@ -203,42 +198,8 @@ class PCPCheckAndHeal extends TreeMapWithStages {
203198 * The tag is generated by an instance of `QuoteTypeTags` directly if the splice is explicit
204199 * or indirectly by `tryHeal`.
205200 */
206- private def healType (pos : SrcPos )(using Context ) = new TypeMap {
207- def apply (tp : Type ): Type =
208- tp match
209- case tp : TypeRef =>
210- healTypeRef(tp)
211- case tp @ TermRef (NoPrefix , _) if ! tp.symbol.isStatic && level > levelOf(tp.symbol) =>
212- levelError(tp.symbol, tp, pos)
213- case tp : AnnotatedType =>
214- derivedAnnotatedType(tp, apply(tp.parent), tp.annot)
215- case _ =>
216- mapOver(tp)
217-
218- private def healTypeRef (tp : TypeRef ): Type =
219- tp.prefix match
220- case prefix : TermRef if tp.symbol.isTypeSplice =>
221- checkNotWildcardSplice(tp)
222- if level == 0 then tp else getQuoteTypeTags.getTagRef(prefix)
223- case prefix : TermRef if ! prefix.symbol.isStatic && level > levelOf(prefix.symbol) =>
224- dealiasAndTryHeal(prefix.symbol, tp, pos)
225- case NoPrefix if level > levelOf(tp.symbol) && ! tp.typeSymbol.hasAnnotation(defn.QuotedRuntime_SplicedTypeAnnot ) =>
226- dealiasAndTryHeal(tp.symbol, tp, pos)
227- case prefix : ThisType if level > levelOf(prefix.cls) && ! tp.symbol.isStatic =>
228- dealiasAndTryHeal(tp.symbol, tp, pos)
229- case _ =>
230- mapOver(tp)
231-
232- private def dealiasAndTryHeal (sym : Symbol , tp : TypeRef , pos : SrcPos )(using Context ): Type =
233- val tp1 = tp.dealias
234- if tp1 != tp then apply(tp1)
235- else tryHeal(tp.symbol, tp, pos)
236-
237- private def checkNotWildcardSplice (splice : TypeRef )(using Context ): Unit =
238- splice.prefix.termSymbol.info.argInfos match
239- case (tb : TypeBounds ) :: _ => report.error(em " Cannot splice $splice because it is a wildcard type " , pos)
240- case _ =>
241- }
201+ protected def healType (pos : SrcPos )(using Context ) =
202+ new HealType (pos)
242203
243204 /** Check level consistency of terms references */
244205 private def checkLevelConsistency (tree : Ident | This )(using Context ): Unit =
@@ -257,33 +218,6 @@ class PCPCheckAndHeal extends TreeMapWithStages {
257218 traverseChildren(tp)
258219 }.traverse(tree.tpe)
259220
260- /** Try to heal reference to type `T` used in a higher level than its definition.
261- * Returns a reference to a type tag generated by `QuoteTypeTags` that contains a
262- * reference to a type alias containing the equivalent of `${summon[quoted.Type[T]]}`.
263- * Emits and error if `T` cannot be healed and returns `T`.
264- */
265- protected def tryHeal (sym : Symbol , tp : TypeRef , pos : SrcPos )(using Context ): TypeRef = {
266- val reqType = defn.QuotedTypeClass .typeRef.appliedTo(tp)
267- val tag = ctx.typer.inferImplicitArg(reqType, pos.span)
268- tag.tpe match
269-
270- case tp : TermRef =>
271- ctx.typer.checkStable(tp, pos, " type witness" )
272- getQuoteTypeTags.getTagRef(tp)
273- case _ : SearchFailureType =>
274- report.error(
275- ctx.typer.missingArgMsg(tag, reqType, " " )
276- .prepend(i " Reference to $tp within quotes requires a given $reqType in scope. \n " )
277- .append(" \n " ),
278- pos)
279- tp
280- case _ =>
281- report.error(em """ Reference to $tp within quotes requires a given $reqType in scope.
282- |
283- | """ , pos)
284- tp
285- }
286-
287221 private def levelError (sym : Symbol , tp : Type , pos : SrcPos )(using Context ): tp.type = {
288222 def symStr =
289223 if (! tp.isInstanceOf [ThisType ]) sym.show
@@ -301,7 +235,6 @@ class PCPCheckAndHeal extends TreeMapWithStages {
301235 | - but the access is at level $level. $hint""" , pos)
302236 tp
303237 }
304-
305238}
306239
307240object PCPCheckAndHeal {
0 commit comments