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
MatchError in immutable.HashMap.merged #9895
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9895?orig=1 |
Andrey Ivanov (a.nigredo-at-gmail.com) said: |
Yaroslav Ulanovych (yarulan) said (edited by @SethTisue on Aug 19, 2016 4:02:31 PM UTC): import scala.collection.immutable.HashMap
val m1 = HashMap[String, Seq[Int]]().updated("0", Seq(0))
val m2 = HashMap[String, Seq[Int]]().updated("0", Seq(1))
// println(m1)
// println(m2)
m1.merged(m2) {
case ((k, v1), (_, v2)) => (k, v1 ++ v2)
} Exception disappears if uncomment println statements |
@SethTisue said: |
Yaroslav Ulanovych (yarulan) said (edited on Aug 19, 2016 4:54:08 PM UTC): |
Andriy Plokhotnyuk (plokhotnyuk) said: 07:37:12 ~/Downloads/scala-2.9.3/bin$ cd ../../scala-2.10.1/bin
07:37:16 ~/Downloads/scala-2.10.1/bin$ ./scala
Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_74).
Type in expressions to have them evaluated.
Type :help for more information.
scala> [init] error: error while loading AnnotatedElement, class file '/usr/lib/jvm/jdk1.8.0_74/jre/lib/rt.jar(java/lang/reflect/AnnotatedElement.class)' is broken
(class java.lang.RuntimeException/bad constant pool tag 18 at byte 76)
[init] error: error while loading CharSequence, class file '/usr/lib/jvm/jdk1.8.0_74/jre/lib/rt.jar(java/lang/CharSequence.class)' is broken
(class java.lang.RuntimeException/bad constant pool tag 18 at byte 10)
:paste
// Entering paste mode (ctrl-D to finish)
import scala.collection.immutable.HashMap
val m1 = HashMap[String, Seq[Int]]().updated("0", Seq(0))
val m2 = HashMap[String, Seq[Int]]().updated("0", Seq(1))
// println(m1)
// println(m2)
m1.merged(m2) {
case ((k, v1), (_, v2)) => (k, v1 ++ v2)
}
// Exiting paste mode, now interpreting.
scala.MatchError: (null,null) (of class scala.Tuple2)
at $anonfun$1.apply(<console>:14)
at $anonfun$1.apply(<console>:14)
at scala.collection.immutable.HashMap$$anon$2$$anon$3.apply(HashMap.scala:139)
at scala.collection.immutable.HashMap$HashMap1.updated0(HashMap.scala:206)
at scala.collection.immutable.HashMap$HashMap1.merge0(HashMap.scala:228)
at scala.collection.immutable.HashMap.merged(HashMap.scala:106) |
Andriy Plokhotnyuk (plokhotnyuk) said: 08:02:51 ~$ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
08:02:55 ~$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions for evaluation. Or try :help.
scala> :paste
// Entering paste mode (ctrl-D to finish)
import scala.collection.immutable.HashMap
val m1 = HashMap[String, Seq[Int]]().updated("0", Seq(0))
val m2 = HashMap[String, Seq[Int]]().updated("0", Seq(1))
// println(m1)
// println(m2)
m1.merged(m2) {
case ((k, v1), (_, v2)) => (k, v1 ++ v2)
}
// Exiting paste mode, now interpreting.
scala.MatchError: (null,null) (of class scala.Tuple2)
at $anonfun$1.apply(<console>:18)
at $anonfun$1.apply(<console>:18)
at scala.collection.immutable.HashMap$$anon$2$$anon$3.apply(HashMap.scala:150)
at scala.collection.immutable.HashMap$HashMap1.updated0(HashMap.scala:200)
at scala.collection.immutable.HashMap$HashMap1.merge0(HashMap.scala:225)
at scala.collection.immutable.HashMap.merged(HashMap.scala:117)
... 37 elided
|
@SethTisue said (edited on Aug 30, 2016 2:02:21 AM UTC): |
@som-snytt said: HashMap.toString uses TraversableOnce that just iterates building the string. (Repl also prints values.) |
@SethTisue said: |
@som-snytt said: Many repros have proved sensitive to REPL because of toString effects. Recently ameliorated was the only puzzler with bleep in the title, http://scalapuzzlers.com/#pzzlr-025 Instead of using the paste command, you can paste at the prompt and then run silent, run deep: scala> m1.merged(m2) {
| case ((k, v1), (_, v2)) => (k, v1 ++ v2)
| }
res0: scala.collection.immutable.HashMap[String,Seq[Int]] = Map(0 -> List(0, 1))
scala> :silent
scala> :replay
Replaying: import scala.collection.immutable.HashMap
Replaying: val m1 = HashMap[String, Seq[Int]]().updated("0", Seq(0))
Replaying: val m2 = HashMap[String, Seq[Int]]().updated("0", Seq(1))
Replaying: m1.merged(m2) {
case ((k, v1), (_, v2)) => (k, v1 ++ v2)
}
scala.MatchError: (null,null) (of class scala.Tuple2)
at $anonfun$1.apply(<console>:15)
at $anonfun$1.apply(<console>:15)
at scala.collection.immutable.HashMap$$anon$2$$anon$3.apply(HashMap.scala:150)
at scala.collection.immutable.HashMap$HashMap1.updated0(HashMap.scala:200)
at scala.collection.immutable.HashMap$HashMap1.merge0(HashMap.scala:225)
at scala.collection.immutable.HashMap.merged(HashMap.scala:117)
... 40 elided |
@SethTisue said: |
Seth Bromberger (sbromberger) said: |
I get following error when run a code below:
But it works fine if instead of merge2 I call merge function.
The text was updated successfully, but these errors were encountered: