Skip to content

Commit

Permalink
Add hint for nested quotes missing staged Quotes (#18755)
Browse files Browse the repository at this point in the history
Fix #17338
  • Loading branch information
nicolasstucki committed Oct 26, 2023
2 parents 8046a8b + d95e7a7 commit 94f5cdb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ class CrossStageSafety extends TreeMapWithStages {
"\n\n" +
"Hint: Staged references to inline definition in quotes are only inlined after the quote is spliced into level 0 code by a macro. " +
"Try moving this inline definition in a statically accessible location such as an object (this definition can be private)."
else if level > 0 && sym.info.derivesFrom(defn.QuotesClass) then
s"""\n
|Hint: Nested quote needs a local context defined at level $level.
|One way to introduce this context is to give the outer quote the type `Expr[Quotes ?=> Expr[T]]`.""".stripMargin
else ""
report.error(
em"""access to $symStr from wrong staging level:
Expand Down
9 changes: 9 additions & 0 deletions tests/neg-macros/i17338.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Error: tests/neg-macros/i17338.scala:4:5 ----------------------------------------------------------------------------
4 | '{ '{ 1 } } // error
| ^
| access to parameter quotes from wrong staging level:
| - the definition is at level 0,
| - but the access is at level 1.
|
| Hint: Nested quote needs a local context defined at level 1.
| One way to introduce this context is to give the outer quote the type `Expr[Quotes ?=> Expr[T]]`.
4 changes: 4 additions & 0 deletions tests/neg-macros/i17338.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import scala.quoted.*

def test(using quotes: Quotes): Expr[Expr[Int]] =
'{ '{ 1 } } // error

0 comments on commit 94f5cdb

Please sign in to comment.