@@ -176,7 +176,12 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
176176 if (! sym.exists || levelOK(sym) || isStaticPathOK(tp) || isStaticNew(tp))
177177 None
178178 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, " " )
180185 else if (! sym.owner.isStaticOwner) // non-top level class reference that is phase inconsistent
181186 levelError(sym, tp, pos, " " )
182187 else
@@ -202,40 +207,29 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
202207 sym.is(Package ) || sym.owner.isStaticOwner || levelOK(sym.owner)
203208 }
204209
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.
206211 * @return None if successful
207212 * @return Some(msg) if unsuccessful where `msg` is a potentially empty error message
208213 * to be added to the "inconsistent phase" message.
209214 */
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 {
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- }
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, " " )}""" )
236227 case _ =>
237- levelError(sym, tp, pos, " " )
238- }
228+ levelError(sym, tp, pos,
229+ i """
230+ |
231+ | The access would be accepted with a given $reqType""" )
232+ }
239233
240234 private def levelError (sym : Symbol , tp : Type , pos : SourcePosition , errMsg : String )(given Context ) = {
241235 def symStr =
0 commit comments