HairyFotr / linter

Static Analysis Compiler Plugin for Scala
Apache License 2.0
268 stars 34 forks source link

VariableAssignedUnusedValue false positive #21

Closed iphydf closed 9 years ago

iphydf commented 9 years ago

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)
  }
HairyFotr commented 9 years ago

Thanks a lot for the report, the issue is fixed in version 0.1.11