@@ -38,12 +38,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
38
38
39
39
private val InAnnotation = Property .Key [Unit ]()
40
40
41
- private [this ] var inQuoteOrSplice = false
42
-
43
41
override def transform (tree : Tree )(implicit ctx : Context ): Tree =
44
42
if (tree.source != ctx.source && tree.source.exists)
45
43
transform(tree)(ctx.withSource(tree.source))
46
- else if ! inQuoteOrSplice then
44
+ else if ! isInQuoteOrSplice then
47
45
checkAnnotations(tree)
48
46
super .transform(tree)
49
47
else tree match {
@@ -54,11 +52,9 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
54
52
else TypeTree (healedType).withSpan(tree.span)
55
53
56
54
case _ : This =>
57
- if level != - 1 && level != levelOf(tree.symbol) then
58
- levelError(tree.symbol, tree.tpe, tree.sourcePos, " " )
59
- tree
55
+ tree.withType(healTermType(tree.sourcePos)(tree.tpe))
60
56
case _ : Ident =>
61
- checkTermLevel( tree) .withType(healTermType(tree.sourcePos)(tree.tpe))
57
+ tree.withType(healTermType(tree.sourcePos)(tree.tpe))
62
58
63
59
// Remove inline defs in quoted code. Already fully inlined.
64
60
case tree : DefDef if tree.symbol.is(Inline ) && level > 0 => EmptyTree
@@ -79,16 +75,14 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
79
75
/** Transform quoted trees while maintaining phase correctness */
80
76
override protected def transformQuotation (body : Tree , quote : Tree )(implicit ctx : Context ): Tree = {
81
77
val taggedTypes = new PCPCheckAndHeal .QuoteTypeTags (quote.span)(using ctx)
78
+
82
79
if (ctx.property(InAnnotation ).isDefined)
83
80
ctx.error(" Cannot have a quote in an annotation" , quote.sourcePos)
84
81
85
82
val contextWithQuote =
86
83
if level == 0 then contextWithQuoteTypeTags(taggedTypes)(quoteContext)
87
84
else quoteContext
88
- val inQuoteOrSpliceOld = inQuoteOrSplice
89
- inQuoteOrSplice = true
90
85
val body1 = transform(body)(contextWithQuote)
91
- inQuoteOrSplice = inQuoteOrSpliceOld
92
86
val body2 =
93
87
taggedTypes.getTypeTags match
94
88
case Nil => body1
@@ -103,10 +97,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
103
97
* - If inside of a macro definition, check the validity of the macro.
104
98
*/
105
99
protected def transformSplice (body : Tree , splice : Tree )(implicit ctx : Context ): Tree = {
106
- val inQuoteOrSpliceOld = inQuoteOrSplice
107
- inQuoteOrSplice = true
108
100
val body1 = transform(body)(spliceContext)
109
- inQuoteOrSplice = inQuoteOrSpliceOld
110
101
splice match {
111
102
case Apply (fun @ TypeApply (_, _ :: Nil ), _) if splice.isTerm =>
112
103
// Type of the splice itsel must also be healed
@@ -154,9 +145,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
154
145
tryHeal(tp.symbol, tp, pos).getOrElse(tp)
155
146
case _ =>
156
147
mapOver(tp)
157
- case tp : ThisType if level != levelOf(tp.cls) =>
158
- if level != - 1 then // Ok after inlined
159
- assert(levelError(tp.cls, tp, pos, " " ).isEmpty)
148
+ case tp : ThisType if level != - 1 && level != levelOf(tp.cls) =>
149
+ levelError(tp.cls, tp, pos, " " )
160
150
tp
161
151
case tp : AnnotatedType =>
162
152
val newAnnotTree = transform(tp.annot.tree)
@@ -170,22 +160,17 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
170
160
tp match
171
161
case tp @ TypeRef (NoPrefix , _) if level > levelOf(tp.symbol) =>
172
162
tryHeal(tp.symbol, tp, pos).getOrElse(tp)
163
+ case tp @ TermRef (NoPrefix , _) if ! tp.symbol.isStatic && level != levelOf(tp.symbol) =>
164
+ levelError(tp.symbol, tp, pos, " " )
165
+ tp
166
+ case tp : ThisType if level != - 1 && level != levelOf(tp.cls) =>
167
+ levelError(tp.cls, tp, pos, " " )
168
+ tp
173
169
case _ =>
174
170
if tp.typeSymbol.is(Package ) then tp
175
171
else mapOver(tp)
176
172
}
177
173
178
- private def checkTermLevel (tree : Tree )(using Context ): tree.type = {
179
- new TypeTraverser {
180
- def traverse (tp : Type ): Unit =
181
- tp match
182
- case tp @ TermRef (NoPrefix , _) if ! tp.symbol.isStatic && level != levelOf(tp.symbol) =>
183
- levelError(tree.symbol, tree.tpe, tree.sourcePos, " " )
184
- case _ => traverseChildren(tp)
185
- }.traverse(tree.tpe)
186
- tree
187
- }
188
-
189
174
// TODO return new type or else old?
190
175
protected def tryHeal (sym : Symbol , tp : TypeRef , pos : SourcePosition )(implicit ctx : Context ): Option [TypeRef ] = {
191
176
val reqType = defn.QuotedTypeClass .typeRef.appliedTo(tp)
0 commit comments