Skip to content

Commit ddc4dc9

Browse files
Merge pull request #9199 from dotty-staging/fix-#9197
Fix #9197: Fix documentation and improve error message
2 parents 6b03fbd + b1666e8 commit ddc4dc9

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
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

docs/docs/reference/metaprogramming/macros.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ It is possible to convert any `Expr[T => R]` into `Expr[T] => Expr[R]` and back.
139139
These conversions can be implemented as follows:
140140

141141
```scala
142-
def to[T, R](f: Expr[T] => Expr[R])(using QuoteContext): Expr[T => R] =
142+
def to[T: Type, R: Type](f: Expr[T] => Expr[R])(using QuoteContext): Expr[T => R] =
143143
'{ (x: T) => ${ f('x) } }
144144

145-
def from[T, R](f: Expr[T => R])(using QuoteContext): Expr[T] => Expr[R] =
145+
def from[T: Type, R: Type](f: Expr[T => R])(using QuoteContext): Expr[T] => Expr[R] =
146146
(x: Expr[T]) => '{ $f($x) }
147147
```
148148

0 commit comments

Comments
 (0)