Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hint for nested quotes missing staged Quotes #18755

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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