How do I properly pattern match a TypeRepr
on a higher-kinded type? Existentials successfully match for classes, but when I try with a type I get the compiler error unreducible application of higher-kinded type writetype.Foo to wildcard arguments
import scala.quoted.*
type Foo[X]
class Bar[X]
inline def writeType[T]: String = ${writeTypeImpl[T]}
def writeTypeImpl[T](using Type[T], Quotes): Expr[String] =
import quotes.reflect.*
val tpe = TypeRepr.of[T]
val s = tpe.asType match
//case '[Foo[?]] => "FooSuccess"
case '[Bar[?]] => "BarSuccess"
case _ => "Fail"
Expr(s)
This is the answer you need :
You have to use a trait
or abstract class
or Foo[A]
where is a concrete type (or type parameter)