I'm writing a Scala subroutine to construct a TypeTag[Map[_<: A, _<: B]] from 2 typetags:
tag1: TypeTag[Iterable[_<: A]]
tag2: TypeTag[Iterable[_<: B]]
The upperbound is necessary because both A and B are declared as covariant, yet TypeTag[T] is invariant.
I'm trying to use case match to get implicit type variables of A and B, but found that type pattern match in Scala is relatively week. Namely, the folloing code fails to be compiled:
(tag1, tag2) match {
case (tt1: TypeTag[Iterable[t1]], tt2: TypeTag[Iterable[t2]]) =>
implicit val t1 = tt1
implicit val t2 = tt2
ScalaReflection.universe.typeTag[Map[t1, t2]]
}
because t1 and t2 cannot be resolved. What should I do to fix-circumvent this?
Aucun commentaire:
Enregistrer un commentaire