scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

False negative "mutated but not read" when read is RHS of assign

Open durban opened this issue 1 month ago • 3 comments

Compiler version

3.3.7

Minimized code

class Foo {
  def foo(): Any = {
    var i = 0 // <- warning here
    val f = () => i += 1
    f
  }
}

Output

[warn] -- [E198] Unused Symbol Warning: .../ThunkSuite.scala:3:8
[warn] 3 |    var i = 0
[warn]   |        ^
[warn]   |        unused local definition

Expectation

No warning (as i is not unused; in fact, if I remove i, that results in an error).

Related: https://github.com/typelevel/cats-effect/pull/4519

durban avatar Oct 27 '25 20:10 durban