My application needs to use Compiler staging vs the normal macro entry points. (Long discussion involving what is knowable at runtime and what isn't, but take it as a given here.)
The run fn(), per API spec, gives you Quotes and nothing more. You do your work and produce an Expr. I need TypeRepr[T] in my function but it won't let me create Type[T]. How can I create Type[T] in the function?
def inTermsOf[T](className: String): RType[?] =
import scala.quoted.staging.*
given Compiler = Compiler.make(getClass.getClassLoader)
val newRType = {
val fn = (quotes: Quotes) ?=> {
import quotes.reflect.*
// Tried this too--same error
implicit val tt = Type.of[T]
val traitRepr = TypeRepr.of[T](using Type.of[T]))
// ERROR: Reference to T within quotes requires a given scala.quoted.Type[T] in scope.
//...more code...
}
run(fn)
}