Skip to content

Commit 94f5cdb

Browse files
Add hint for nested quotes missing staged Quotes (#18755)
Fix #17338
2 parents 8046a8b + d95e7a7 commit 94f5cdb

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ class CrossStageSafety extends TreeMapWithStages {
228228
"\n\n" +
229229
"Hint: Staged references to inline definition in quotes are only inlined after the quote is spliced into level 0 code by a macro. " +
230230
"Try moving this inline definition in a statically accessible location such as an object (this definition can be private)."
231+
else if level > 0 && sym.info.derivesFrom(defn.QuotesClass) then
232+
s"""\n
233+
|Hint: Nested quote needs a local context defined at level $level.
234+
|One way to introduce this context is to give the outer quote the type `Expr[Quotes ?=> Expr[T]]`.""".stripMargin
231235
else ""
232236
report.error(
233237
em"""access to $symStr from wrong staging level:

tests/neg-macros/i17338.check

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Error: tests/neg-macros/i17338.scala:4:5 ----------------------------------------------------------------------------
2+
4 | '{ '{ 1 } } // error
3+
| ^
4+
| access to parameter quotes from wrong staging level:
5+
| - the definition is at level 0,
6+
| - but the access is at level 1.
7+
|
8+
| Hint: Nested quote needs a local context defined at level 1.
9+
| One way to introduce this context is to give the outer quote the type `Expr[Quotes ?=> Expr[T]]`.

tests/neg-macros/i17338.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import scala.quoted.*
2+
3+
def test(using quotes: Quotes): Expr[Expr[Int]] =
4+
'{ '{ 1 } } // error

0 commit comments

Comments
 (0)