Skip to content

Commit

Permalink
Backport "Add hint for nested quotes missing staged Quotes" to LTS (#…
Browse files Browse the repository at this point in the history
…20743)

Backports #18755 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 23, 2024
2 parents 53fff81 + 5f83eb3 commit 7ee6c41
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 @@ -214,6 +214,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 7ee6c41

Please sign in to comment.