Pattern matching a Type[T]
on classes and traits with type parameters works just fine using an existential, but when I try to pattern match a higher-kinded type I get the compiler error unreducible application of higher-kinded type Foo to wildcard arguments,
which seems to indicate the compiler is looking for a concrete type and it cannot construct one with the wildcard argument. Is there a way to pattern match without a concrete type?
The example below demonstrates the problem:
import scala.quoted.*
type Foo[X]
class Bar[X]
trait Baz[X]
inline def writeType[T]: String = ${writeTypeImpl[T]}
def writeTypeImpl[T](using t: Type[T])(using Quotes): Expr[String] =
import quotes.reflect.*
val s = t match
case '[Foo[?]] => "FooSuccess" //compiler error, but other two successfully match
case '[Bar[?]] => "BarSuccess"
case '[Baz[?]] => "BazSuccess"
case _ => "Fail"
Expr(s)