E179: Match Type Scrutinee Cannot Be Higher-Kinded
This error occurs when you try to use a higher-kinded type as the scrutinee (the type being matched) in a match type definition.
Match types in Scala 3 only support proper types (types of kind *) as their scrutinee. Higher-kinded types (types that take type parameters, like F[_]) cannot be used directly as the scrutinee.
Example
object Test:
type HigherKindedMatch[X[_]] = X match
case _ => Int
Error
-- [E179] Type Error: example.scala:2:33 ---------------------------------------
2 | type HigherKindedMatch[X[_]] = X match
| ^
| the scrutinee of a match type cannot be higher-kinded
Solution
Use a proper type (kind *) as the scrutinee by applying the higher-kinded type to a type parameter:
object Test:
type AppliedMatch[X[_], A] = X[A] match
case List[a] => Int
case Option[a] => String
Or match on a specific applied type:
object Test:
type ConcreteMatch[X] = X match
case List[a] => Int
case Option[a] => String
In this article