Skip to content

Scalastyle proposed rules (Types)

sschaef edited this page Dec 12, 2012 · 3 revisions

This page contains proposed rules for Scalastyle, for the category Types

Types

Type Annotation

Checks that types are annotated with the colon in the correct place This passes: def method(): Int = 1 This fails def method() : Int = 1 Rationale: This is standard behaviour in the scala library, and avoids confusion in certain circumstances.

Type Parameter Shadowing

Checks that a type parameter does not shadow another one:

def meth[A](a: A, f: A => A): List[A] = {
  val as = List(f(a))
  def inner[A](a: A) = f(a)
  inner(a) :: as
}

This code example does not compile and fails with the following cryptic error message:

<console>:10: error: type mismatch;
 found   : a.type (with underlying type A)
 required: A
         def inner[A](a: A) = f(a)
                                ^

Scalasyle can do a better job and raise a warning on the declaration of the type parameter of inner.