diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 22ec107aeae8..906fcde97255 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -1,6 +1,7 @@ package scala.quoted import scala.annotation.experimental +import scala.annotation.implicitNotFound import scala.reflect.TypeTest /** Current Quotes in scope @@ -21,7 +22,23 @@ transparent inline def quotes(using q: Quotes): q.type = q * * It contains the low-level Typed AST API metaprogramming API. * This API does not have the static type guarantees that `Expr` and `Type` provide. + * + * `Quotes` are generated from an enclosing `${ ... }` or `scala.staging.run`. For example: + * ```scala sc:nocompile + * import scala.quoted._ + * inline def myMacro: Expr[T] = + * ${ /* (quotes: Quotes) ?=> */ myExpr } + * def myExpr(using Quotes): Expr[T] = + * '{ f(${ /* (quotes: Quotes) ?=> */ myOtherExpr }) } + * } + * def myOtherExpr(using Quotes): Expr[U] = '{ ... } + * ``` */ +@implicitNotFound("""No given instance of type scala.quoted.Quotes was found. + +Quotes are generated from an enclosing splice `$ { ... }` or `scala.staging.run` call. +Maybe that splice `$ { ... }` or `scala.staging.run` is missing? +""") trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => // Extension methods for `Expr[T]` diff --git a/tests/neg-macros/i16888.check b/tests/neg-macros/i16888.check new file mode 100644 index 000000000000..b71c836fd016 --- /dev/null +++ b/tests/neg-macros/i16888.check @@ -0,0 +1,7 @@ +-- [E172] Type Error: tests/neg-macros/i16888.scala:1:38 --------------------------------------------------------------- +1 |def test = summon[scala.quoted.Quotes] // error + | ^ + | No given instance of type scala.quoted.Quotes was found. + | + | Quotes are generated from an enclosing splice `$ { ... }` or `scala.staging.run` call. + | Maybe that splice `$ { ... }` or `scala.staging.run` is missing? diff --git a/tests/neg-macros/i16888.scala b/tests/neg-macros/i16888.scala new file mode 100644 index 000000000000..9d3fd0f2f57e --- /dev/null +++ b/tests/neg-macros/i16888.scala @@ -0,0 +1 @@ +def test = summon[scala.quoted.Quotes] // error diff --git a/tests/neg-macros/i6436.check b/tests/neg-macros/i6436.check index 43e93b2e64e5..b7a7b157a9ec 100644 --- a/tests/neg-macros/i6436.check +++ b/tests/neg-macros/i6436.check @@ -1,7 +1,10 @@ -- [E172] Type Error: tests/neg-macros/i6436.scala:5:9 ----------------------------------------------------------------- 5 | case '{ StringContext(${Varargs(parts)}*) } => // error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | No given instance of type scala.quoted.Quotes was found + | No given instance of type scala.quoted.Quotes was found. + | + | Quotes are generated from an enclosing splice `$ { ... }` or `scala.staging.run` call. + | Maybe that splice `$ { ... }` or `scala.staging.run` is missing? -- [E006] Not Found Error: tests/neg-macros/i6436.scala:6:34 ----------------------------------------------------------- 6 | val ps: Seq[Expr[String]] = parts // error | ^^^^^