Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMap Key types are erased and allow for unsafe type cast #554

Open
stewSquared opened this Issue Feb 29, 2016 · 0 comments

Comments

Projects
None yet
2 participants
@stewSquared
Copy link

stewSquared commented Feb 29, 2016

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. KeyInt extends Key[Int] (if Key were not a case class)

It should probably be documented somewhere that higher-kinded types are to be used as keys with caution in the current design of HMap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.