I'm trying to write some generic testing software for various types using a parameterized base class. I get match errors though on code which I don't believe should be possible.
abstract class AbstractTypeTest[TestType: ClassTag, DriverType <: AnyRef : ClassTag](
def checkNormalRowConsistency(
expectedKeys: Seq[TestType],
results: Seq[(TestType, TestType, TestType)]) {
val foundKeys = results.filter {
case (pkey: TestType, ckey: TestType, data: TestType) => expectedKeys.contains(pkey)
case x => throw new RuntimeException(s"${x.getClass}")
}
foundKeys should contain theSameElementsAs expectedKeys.map(x => (x, x, x))
}
}
An extending class specifies the parameter of TypeTest but this code block throws Runtime Exceptions (because we don't match what I believe should be the only allowed type here)
The output of the above code with some extended types works but with others it does not, in this case I'm extending this class with TestType --> Int
[info] java.lang.RuntimeException: class scala.Tuple3
I can remove the type on the filter and the ScalaTest check works perfectly but I'd like to understand why the MatchError occurs.