Skip to content

Commit b1666e8

Browse files
committed
Improve healing failure message
When healing is attempted and quote.Type is not available, the levels are irrelevant for the user. The users need to know that this quote.Type is missing and can fix the issue by adding it. Otherwise, they need to know that a type that was not supposed to be in the quotes is used within them.
1 parent b07b909 commit b1666e8

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
188188
case _ =>
189189
mapOver(tp)
190190
case tp: ThisType if level != -1 && level != levelOf(tp.cls) =>
191-
levelError(tp.cls, tp, pos, "")
191+
levelError(tp.cls, tp, pos)
192192
case tp: AnnotatedType =>
193193
val newAnnotTree = transform(tp.annot.tree)
194194
derivedAnnotatedType(tp, apply(tp.parent), tp.annot.derivedAnnotation(newAnnotTree))
@@ -203,9 +203,9 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
203203
case tp @ TypeRef(NoPrefix, _) if level > levelOf(tp.symbol) =>
204204
tryHeal(tp.symbol, tp, pos)
205205
case tp @ TermRef(NoPrefix, _) if !tp.symbol.isStatic && level != levelOf(tp.symbol) =>
206-
levelError(tp.symbol, tp, pos, "")
206+
levelError(tp.symbol, tp, pos)
207207
case tp: ThisType if level != -1 && level != levelOf(tp.cls) =>
208-
levelError(tp.cls, tp, pos, "")
208+
levelError(tp.cls, tp, pos)
209209
case _ =>
210210
if tp.typeSymbol.is(Package) then tp
211211
else mapOver(tp)
@@ -225,27 +225,27 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
225225
checkStable(tp, pos, "type witness")
226226
getQuoteTypeTags.getTagRef(tp)
227227
case _: SearchFailureType =>
228-
levelError(sym, tp, pos,
229-
i"""
230-
|
231-
| The access would be accepted with the right type tag, but
232-
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
228+
ctx.error(i"""Reference to $tp withing quotes requires a $reqType in scope.
229+
|${ctx.typer.missingArgMsg(tag, reqType, "")}
230+
|
231+
|""", pos)
232+
tp
233233
case _ =>
234-
levelError(sym, tp, pos,
235-
i"""
236-
|
237-
| The access would be accepted with a given $reqType""")
234+
ctx.error(i"""Reference to $tp withing quotes requires a $reqType in scope.
235+
|
236+
|""", pos)
237+
tp
238238
}
239239

240-
private def levelError(sym: Symbol, tp: Type, pos: SourcePosition, errMsg: String)(using Context): tp.type = {
240+
private def levelError(sym: Symbol, tp: Type, pos: SourcePosition)(using Context): tp.type = {
241241
def symStr =
242242
if (!tp.isInstanceOf[ThisType]) sym.show
243243
else if (sym.is(ModuleClass)) sym.sourceModule.show
244244
else i"${sym.name}.this"
245245
ctx.error(
246246
em"""access to $symStr from wrong staging level:
247247
| - the definition is at level ${levelOf(sym)},
248-
| - but the access is at level $level.$errMsg""", pos)
248+
| - but the access is at level $level.""", pos)
249249
tp
250250
}
251251

0 commit comments

Comments
 (0)