1

In the Scala 3 console (or in Scastie), when running the following code:

import scala.quoted._

val a = Expr("Hello")

The following error results:

-- Error: ----------------------------------------------------------------------
1 |val a = Expr("Hello")
  |                     ^
  |No given instance of type quoted.Quotes was found for parameter x$3 of method apply in object Expr
1 error found

Is there an additional step that needs to be done to use macros in the console?

user182917
  • 1,688
  • 2
  • 14
  • 17

1 Answers1

2

It turns out I was misunderstanding the quoting mechanism. In the context of a minimal example to run in the console, the quote should have been spliced before returning it:

import scala.quoted.*

def getQuote()(using Quotes) = '{ "a quote" }

inline def getSplice() = ${ getQuote() }

The spliced quote can then be evaluated from the console:

getSplice()     // returns "a quote"

The quote, however, can not be evaluated directly, resulting in the former error:

getQuote()      // errors out
user182917
  • 1,688
  • 2
  • 14
  • 17