scala> import scala.collection.immutable.HashMap; val left = HashMap((1 to 100000).map(x => (x, x)): _*); left.merged(new HashMap[Int, Int])((x, y) => x)
java.lang.RuntimeException: section supposed to be unreachable.
at scala.sys.package$.error(package.scala:30)
at scala.collection.immutable.HashMap$HashTrieMap.merge0(HashMap.scala:955)
at scala.collection.immutable.HashMap.merged(HashMap.scala:142)
... 28 elided
Problem
No exception should be raised
Discussion
Workaround is to use HashMap[Int, Int]() or HashMap.empty[Int, Int], which returns a singleton instance of HashMap.EmptyHashMap.
The bug is due to code paths that check for that eq EmptyHashMap instead of that.isEmpty. These seem limited to the implementation of merged.
This is fixed in 2.13.0 with the new implementation of HashMap. Raising this bug for historical record as I found it while reviewing the old implementation.
thanks Jason! closing as we don't keep 2.12-only tickets open, but perhaps someone on @scala/collections would be interested in attempting a 2.12-only fix
Reproduction steps
Scala version: 2.12.19
Problem
No exception should be raised
Discussion
Workaround is to use
HashMap[Int, Int]()
orHashMap.empty[Int, Int]
, which returns a singleton instance ofHashMap.EmptyHashMap
.The bug is due to code paths that check for
that eq EmptyHashMap
instead ofthat.isEmpty
. These seem limited to the implementation ofmerged
.This is fixed in 2.13.0 with the new implementation of HashMap. Raising this bug for historical record as I found it while reviewing the old implementation.