@@ -140,6 +140,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
140
140
141
141
if (sym.exists && ! sym.isStaticOwner && ! isClassRef && ! levelOK(sym))
142
142
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, " " )
143
145
else
144
146
None
145
147
}
@@ -170,17 +172,6 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
170
172
* to be added to the "inconsistent phase" message.
171
173
*/
172
174
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
175
tp match {
185
176
case tp : TypeRef =>
186
177
if (level == - 1 ) {
@@ -193,19 +184,33 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
193
184
case _ : TermRef =>
194
185
Some (tag.select(tpnme.splice))
195
186
case _ : SearchFailureType =>
196
- levelError(i """
187
+ levelError(sym, tp, pos,
188
+ i """
197
189
|
198
190
| The access would be accepted with the right type tag, but
199
191
| ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
200
192
case _ =>
201
- levelError(i """
193
+ levelError(sym, tp, pos,
194
+ i """
202
195
|
203
196
| The access would be accepted with an implict $reqType""" )
204
197
}
205
198
}
206
199
case _ =>
207
- levelError(" " )
200
+ levelError(sym, tp, pos, " " )
208
201
}
209
202
}
210
203
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
+
211
216
}
0 commit comments