Skip to content

Commit 8fdba71

Browse files
nicolasstuckiWojciechMazur
authored andcommitted
Add hint for nested quotes missing staged Quotes
Fix #17338 [Cherry-picked d95e7a7]
1 parent adbfa5e commit 8fdba71

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ class CrossStageSafety extends TreeMapWithStages {
214214
"\n\n" +
215215
"Hint: Staged references to inline definition in quotes are only inlined after the quote is spliced into level 0 code by a macro. " +
216216
"Try moving this inline definition in a statically accessible location such as an object (this definition can be private)."
217+
else if level > 0 && sym.info.derivesFrom(defn.QuotesClass) then
218+
s"""\n
219+
|Hint: Nested quote needs a local context defined at level $level.
220+
|One way to introduce this context is to give the outer quote the type `Expr[Quotes ?=> Expr[T]]`.""".stripMargin
217221
else ""
218222
report.error(
219223
em"""access to $symStr from wrong staging level:

tests/neg-macros/i17338.check

Lines changed: 9 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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)