@@ -176,7 +176,12 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
176
176
if (! sym.exists || levelOK(sym) || isStaticPathOK(tp) || isStaticNew(tp))
177
177
None
178
178
else if (! sym.isStaticOwner && ! isClassRef)
179
- tryHeal(sym, tp, pos)
179
+ tp match
180
+ case tp : TypeRef =>
181
+ if levelOf(sym).getOrElse(0 ) < level then tryHeal(sym, tp, pos)
182
+ else None
183
+ case _ =>
184
+ levelError(sym, tp, pos, " " )
180
185
else if (! sym.owner.isStaticOwner) // non-top level class reference that is phase inconsistent
181
186
levelError(sym, tp, pos, " " )
182
187
else
@@ -202,42 +207,29 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
202
207
sym.is(Package ) || sym.owner.isStaticOwner || levelOK(sym.owner)
203
208
}
204
209
205
- /** Try to heal phase-inconsistent reference to type `T` using a local type definition.
210
+ /** Try to heal reference to type `T` used in a higher level than its definition.
206
211
* @return None if successful
207
212
* @return Some(msg) if unsuccessful where `msg` is a potentially empty error message
208
213
* to be added to the "inconsistent phase" message.
209
214
*/
210
- protected def tryHeal (sym : Symbol , tp : Type , pos : SourcePosition )(implicit ctx : Context ): Option [Tree ] =
211
- tp match {
212
- case tp : TypeRef =>
213
- if (level == - 1 ) {
214
- assert(ctx.inInlineMethod)
215
- None
216
- }
217
- else if (levelOf(sym).getOrElse(0 ) < level) {
218
- val reqType = defn.QuotedTypeClass .typeRef.appliedTo(tp)
219
- val tag = ctx.typer.inferImplicitArg(reqType, pos.span)
220
- tag.tpe match {
221
- case _ : TermRef =>
222
- Some (tag.select(tpnme.splice))
223
- case _ : SearchFailureType =>
224
- levelError(sym, tp, pos,
225
- i """
226
- |
227
- | The access would be accepted with the right type tag, but
228
- | ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
229
- case _ =>
230
- levelError(sym, tp, pos,
231
- i """
232
- |
233
- | The access would be accepted with an implict $reqType""" )
234
- }
235
- } else {
236
- None
237
- }
215
+ protected def tryHeal (sym : Symbol , tp : TypeRef , pos : SourcePosition )(implicit ctx : Context ): Option [Tree ] = {
216
+ val reqType = defn.QuotedTypeClass .typeRef.appliedTo(tp)
217
+ val tag = ctx.typer.inferImplicitArg(reqType, pos.span)
218
+ tag.tpe match
219
+ case _ : TermRef =>
220
+ Some (tag.select(tpnme.splice))
221
+ case _ : SearchFailureType =>
222
+ levelError(sym, tp, pos,
223
+ i """
224
+ |
225
+ | The access would be accepted with the right type tag, but
226
+ | ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
238
227
case _ =>
239
- levelError(sym, tp, pos, " " )
240
- }
228
+ levelError(sym, tp, pos,
229
+ i """
230
+ |
231
+ | The access would be accepted with a given $reqType""" )
232
+ }
241
233
242
234
private def levelError (sym : Symbol , tp : Type , pos : SourcePosition , errMsg : String )(given Context ) = {
243
235
def symStr =
0 commit comments