@@ -140,6 +140,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
140140
141141 if (sym.exists && ! sym.isStaticOwner && ! isClassRef && ! levelOK(sym))
142142 tryHeal(sym, tp, pos)
143+ else if (sym.exists && ! sym.owner.isStaticOwner && ! levelOK(sym)) // local class reference that is phase
144+ levelError(sym, tp, pos, " " )
143145 else
144146 None
145147 }
@@ -170,17 +172,6 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
170172 * to be added to the "inconsistent phase" message.
171173 */
172174 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- }
184175 tp match {
185176 case tp : TypeRef =>
186177 if (level == - 1 ) {
@@ -193,19 +184,33 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
193184 case _ : TermRef =>
194185 Some (tag.select(tpnme.splice))
195186 case _ : SearchFailureType =>
196- levelError(i """
187+ levelError(sym, tp, pos,
188+ i """
197189 |
198190 | The access would be accepted with the right type tag, but
199191 | ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
200192 case _ =>
201- levelError(i """
193+ levelError(sym, tp, pos,
194+ i """
202195 |
203196 | The access would be accepted with an implict $reqType""" )
204197 }
205198 }
206199 case _ =>
207- levelError(" " )
200+ levelError(sym, tp, pos, " " )
208201 }
209202 }
210203
204+ private def levelError (sym : Symbol , tp : Type , pos : SourcePosition , errMsg : String ) given Context = {
205+ def symStr =
206+ if (! tp.isInstanceOf [ThisType ]) sym.show
207+ else if (sym.is(ModuleClass )) sym.sourceModule.show
208+ else i " ${sym.name}.this "
209+ the[Context ].error(
210+ em """ access to $symStr from wrong staging level:
211+ | - the definition is at level ${levelOf(sym).getOrElse(0 )},
212+ | - but the access is at level $level. $errMsg""" , pos)
213+ None
214+ }
215+
211216}
0 commit comments