E191: Match Type Legacy Pattern
This error occurs when a match type pattern contains an illegal case with an unaccounted type parameter in a contravariant position.
In match types, type parameters extracted from patterns must be properly accounted for. When a type parameter appears in a contravariant position (e.g., inside a Consumer[-T]), the compiler cannot reliably extract it.
Example
class Consumer[-T]
type Illegal[X] = X match
case Consumer[List[t]] => t
Error
-- [E191] Type Error: example.scala:3:20 ---------------------------------------
3 |type Illegal[X] = X match
| ^
| The match type contains an illegal case:
| case Consumer[List[t]] => t
| The pattern contains an unaccounted type parameter `t`.
| (this error can be ignored for now with `-source:3.3`)
|
4 | case Consumer[List[t]] => t
Solution
Extract type parameters from covariant positions instead:
class Consumer[-T]
// Extract from covariant position (List is covariant)
type Legal[X] = X match
case List[t] => t
Or redesign the type structure to avoid contravariant type extraction:
class Producer[+T]
// Type parameter in covariant position
type Extract[X] = X match
case Producer[t] => t
In this article