@@ -138,8 +138,12 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
138
138
/** Is a reference to a class but not `this.type` */
139
139
def isClassRef = sym.isClass && ! tp.isInstanceOf [ThisType ]
140
140
141
- if (sym.exists && ! sym.isStaticOwner && ! isClassRef && ! levelOK(sym))
141
+ if (! sym.exists || levelOK(sym))
142
+ None
143
+ else if (! sym.isStaticOwner && ! isClassRef)
142
144
tryHeal(sym, tp, pos)
145
+ else if (! sym.owner.isStaticOwner) // non-top level class reference that is phase inconsistent
146
+ levelError(sym, tp, pos, " " )
143
147
else
144
148
None
145
149
}
@@ -170,17 +174,6 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
170
174
* to be added to the "inconsistent phase" message.
171
175
*/
172
176
protected def tryHeal (sym : Symbol , tp : Type , pos : SourcePosition )(implicit ctx : Context ): Option [Tree ] = {
173
- def levelError (errMsg : String ) = {
174
- def symStr =
175
- if (! tp.isInstanceOf [ThisType ]) sym.show
176
- else if (sym.is(ModuleClass )) sym.sourceModule.show
177
- else i " ${sym.name}.this "
178
- ctx.error(
179
- em """ access to $symStr from wrong staging level:
180
- | - the definition is at level ${levelOf(sym).getOrElse(0 )},
181
- | - but the access is at level $level. $errMsg""" , pos)
182
- None
183
- }
184
177
tp match {
185
178
case tp : TypeRef =>
186
179
if (level == - 1 ) {
@@ -193,19 +186,33 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
193
186
case _ : TermRef =>
194
187
Some (tag.select(tpnme.splice))
195
188
case _ : SearchFailureType =>
196
- levelError(i """
189
+ levelError(sym, tp, pos,
190
+ i """
197
191
|
198
192
| The access would be accepted with the right type tag, but
199
193
| ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
200
194
case _ =>
201
- levelError(i """
195
+ levelError(sym, tp, pos,
196
+ i """
202
197
|
203
198
| The access would be accepted with an implict $reqType""" )
204
199
}
205
200
}
206
201
case _ =>
207
- levelError(" " )
202
+ levelError(sym, tp, pos, " " )
208
203
}
209
204
}
210
205
206
+ private def levelError (sym : Symbol , tp : Type , pos : SourcePosition , errMsg : String ) given Context = {
207
+ def symStr =
208
+ if (! tp.isInstanceOf [ThisType ]) sym.show
209
+ else if (sym.is(ModuleClass )) sym.sourceModule.show
210
+ else i " ${sym.name}.this "
211
+ the[Context ].error(
212
+ em """ access to $symStr from wrong staging level:
213
+ | - the definition is at level ${levelOf(sym).getOrElse(0 )},
214
+ | - but the access is at level $level. $errMsg""" , pos)
215
+ None
216
+ }
217
+
211
218
}
0 commit comments