The analyser incorrectly thinks that assignments in anonymous inner classes happen directly. Adding an assert(called == 0) between the two adds here works around the problem.
"remove" should "be idempotent" in {
val event = new Event
var called = 0
val id1 = event.add(new Runnable {
override def run(): Unit = called = 1
})
val id2 = event.add(new Runnable {
override def run(): Unit = called = 2 // Variable called has an unused value before this reassign.
})
event.remove(id1)
event.remove(id1)
event.run()
assert(called == 2)
}
The analyser incorrectly thinks that assignments in anonymous inner classes happen directly. Adding an
assert(called == 0)
between the twoadd
s here works around the problem.