% cat /tmp/A.scala

object A{
    def foo() {
        val a = 2

% ./scalac -Xlint /tmp/A.scala

/tmp/A.scala:4: warning: local val in method foo is never used
val a = 2

对于类型推导方面,下面的情况也给出了合适的警告 (在2.10下lint不会警告)

% ./scala -Xlint

scala>  def mycons[B](x:B, xs:List[B]):List[B] = x :: xs

scala> mycons("hi", List(200))
<console>:9: warning: a type was inferred to be `Any`; this may indicate a programming error.
          mycons("hi", List(200))
res0: List[Any] = List(hi, 200)


3 thoughts on “scala2.11编译器对lint的增强

  1. 类型推导方面,在 2.11.0 -M8版本,编译器不会给出警告
    scala> def mycons[B](x:B, xs:List[B]):List[B] = x:: xs
    mycons: [B](x: B, xs: List[B])List[B]

    scala> mycons(“hi”, List(200))
    res1: List[Any] = List(hi, 200)

Leave a Reply

Your email address will not be published. Required fields are marked *