I've been trying to filter a type-level tuple as suggested by the Tuple.filter documentation, but I've been getting the error Type argument Playground.IsString does not conform to upper bound [_] =>> Boolean. Does anyone know what I'm getting wrong?
The expected result is that I should be able to write Filter[("first", 1, "second", 2), IsString] =:= ("first", "second")
Playground example: https://scastie.scala-lang.org/SQzB9zTPT5ueIqOiXfG4KQ
import scala.Tuple.Filter
type IsString[X] = X match {
case String => true
case _ => false
}
abstract class TupleFilter {
val x: Filter[("first", 1, "second", 2), IsString]
}
You can either add upper bound
or add a type lambda into intersection type
& BooleanThe thing is that currently subtyping rules for match types are the following:
https://docs.scala-lang.org/scala3/reference/new-types/match-types.html#subtyping-rules-for-match-types
There is no rule
S match { P1 => T1 ... Pn => Tn } <: TifTi <: Tforiin1..n.