Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
HMap Key types are erased and allow for unsafe type cast #554
Here's a minimal example:
case class Key[T](id: Int) case class Value[T](value: T) class MyMap[K,V] implicit object mapInts extends MyMap[Key[Int], Value[Int]] implicit object mapStrs extends MyMap[Key[String], Value[String]] val map = HMap[MyMap](Key[Int](0) -> Value(3)) val three: String = map.get(Key[String](0)).get.value // java.lang.ClassCastException
Generally, this might be worked around by using an equivalent proper type rather than a type constructor. e.g.
It should probably be documented somewhere that higher-kinded types are to be used as keys with caution in the current design of HMap.