Back to Scala3

E179: Match Type Scrutinee Cannot Be Higher-Kinded

docs/_docs/reference/error-codes/E179.md

3.8.41.4 KB
Original Source

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

scala
object Test:
  type HigherKindedMatch[X[_]] = X match
    case _ => Int

Error

scala
-- [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:

scala
object Test:
  type AppliedMatch[X[_], A] = X[A] match
    case List[a] => Int
    case Option[a] => String

Or match on a specific applied type:

scala
object Test:
  type ConcreteMatch[X] = X match
    case List[a] => Int
    case Option[a] => String
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>