E202: Quoted Type Missing

This error occurs when referencing a type parameter inside a quoted expression ('{ ... }) without a corresponding Type[T] instance in scope.

Since Scala uses type erasure at runtime, type information is lost during execution. When using macros and quotes, the compiler needs a scala.quoted.Type[T] instance to carry the type information into the quoted code.

Example

import scala.quoted.{Expr, Quotes}

case class Thing[T]()

def foo[T](using Quotes): Expr[Thing[T]] = '{ Thing[T]() }

Error

-- [E202] Staging Issue Error: example.scala:5:52 ------------------------------
5 |def foo[T](using Quotes): Expr[Thing[T]] = '{ Thing[T]() }
  |                                                    ^
  |Reference to T within quotes requires a given scala.quoted.Type[T] in scope
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Referencing `T` inside a quoted expression requires a `scala.quoted.Type[T]` to be in scope.
  | Since Scala is subject to erasure at runtime, the type information will be missing during the execution of the code.
  | `scala.quoted.Type[T]` is therefore needed to carry `T`'s type information into the quoted code.
  | Without an implicit `scala.quoted.Type[T]`, the type `T` cannot be properly referenced within the expression.
  | To resolve this, ensure that a `scala.quoted.Type[T]` is available, either through a context-bound or explicitly.
   -----------------------------------------------------------------------------

Explanation

Referencing T inside a quoted expression requires a scala.quoted.Type[T] to be in scope. Since Scala is subject to erasure at runtime, the type information will be missing during the execution of the code. scala.quoted.Type[T] is therefore needed to carry T's type information into the quoted code. Without an implicit scala.quoted.Type[T], the type T cannot be properly referenced within the expression. To resolve this, ensure that a scala.quoted.Type[T] is available, either through a context-bound or explicitly.

Solution

Add a context bound T: Type to make the type information available:

import scala.quoted.{Expr, Quotes, Type}

case class Thing[T]()

def foo[T: Type](using Quotes): Expr[Thing[T]] = '{ Thing[T]() }

Alternatively, you can provide the Type[T] explicitly as a using parameter:

import scala.quoted.{Expr, Quotes, Type}

case class Thing[T]()

def bar[T](using Quotes, Type[T]): Expr[Thing[T]] = '{ Thing[T]() }