I am having a bizarre mistake. One of the case objects (only one) gets null as its value and, obviously, throws Null pointer exceptions later in life. But why?
I tried different things (renaming objects, changing indecision, even rewriting one line twice, getting one of them to compile nice, and the other null ). I cloned the repo to make sure this is not some kind of ridiculous transition effect. Both Scala 2.11.4 and 2.11.5 cause the same thing.
The code is rather twisty and the context that cuts it off makes little sense. But here he is, in case anyone else calls someone.
sealed trait A {} sealed trait B extends A {} sealed trait C { val n: Int } object C { val C1: C = new C { val n = 1 } val C2: C = new C { val n = 2 } val C3: C = new C { val n = 3 } val C4a: C = new C { val n = 4 } val C4b: C = new C { val n = 5 } } class D (depends: Seq[C], f: (Seq[Double]) => Double) { // ...methods removed } sealed trait E { val e: Int = 1 } object D { import C._ private def f( v: Seq[Double] ): Double = 0 private def list( acc: Boolean ) = List( C1, C2, C3, if (acc) C4a else C4b ) case object D1 extends D( list(true), f ) with E // <-- this gets to be 'null'!! case object D2 extends D( list(false), f ) val keys: Seq[D] = List(D1, D2) println(s"D1: $D1") println(s"D2: $D2") assert(D1 != null) // <-- caught here assert(D2 != null) }
I tried to save as many details as possible in the code, if they have any meaning.
What could it be?
I marked it as "heisenbug", but when I compile the material, it is consistent (i.e. successive test runs will always produce the same effect).
EDIT: I initially said that this only happened with sbt test (and not sbt run ), but it is not. Both were equally affected.
EDIT: It seems @ dk14 filed this as Scala issue 9115 . Thanks!
scala heisenbug
akauppi
source share