Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,16 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
if (!tp.isInstanceOf[ThisType]) sym.show
else if (sym.is(ModuleClass)) sym.sourceModule.show
else i"${sym.name}.this"
val hint =
if sym.is(Inline) && levelOf(sym) < level then
"\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 ""
report.error(
em"""access to $symStr from wrong staging level:
| - the definition is at level ${levelOf(sym)},
| - but the access is at level $level.""", pos)
| - but the access is at level $level.$hint""", pos)
tp
}

Expand Down
8 changes: 8 additions & 0 deletions tests/neg-macros/i16532.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Error: tests/neg-macros/i16532.scala:7:13 ---------------------------------------------------------------------------
7 | val x2 = recurseII($a, $b) // error
| ^^^^^^^^^
|access to method recurseII from wrong staging level:
| - the definition is at level 0,
| - but the access is at level 1.
|
|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).
9 changes: 9 additions & 0 deletions tests/neg-macros/i16532.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.quoted.*

def power0Impl(a: Expr[Int], b: Expr[Int])(using Quotes): Expr[Int] =
inline def recurseII(a:Int, n:Int): Int = ???

'{
val x2 = recurseII($a, $b) // error
x2
}