scala does not warn about unused computation or va

2019-06-20 15:10发布

问题:

I have this little scala example:

object Test {
  def add(x: Int, y: Int) = {
    val z = x - y
    x match {
      case 0 => 0 - y
      case 1 => 1 - y
      case _ => x - y
    }
    x + y
  }

  def main(args: Array[String]) {
    println(add(5, 6))
  }
}

I feel that scala should warn about 'z' and the 'x match ...' being unused. I did not notice any compiler options to turn on more warnings. I'm using scala 2.10.1.

Thoughts? Thanks!

回答1:

As you can see here, "unused" warnings will be introduced in the next version of scala, 2.11.

Warn about unused private / local terms and types, and unused imports, under -Xlint

You can try them using the last milestone.