Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Scala annotations modify the compiler's messages?

I know about two:

  • @deprecated("use blabla instead") is used to add an explanation to the warning output by the compiler when the annotated definition is used in client code.
  • @implicitNotFound(msg = "more meaningful explanation") is used to output an additional error message whenever an implicit of the type of the annotated definition cannot be found. Looking at CanBuildFrom, msg can contain placeholders of the type ${A} if A is the name of a type parameter of the annotated type, which is filled in by the compiler with the actual expected type, e.g.:

    @implicitNotFound(msg = "Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${To}.")
    trait CanBuildFrom[-From, -Elem, +To] { ... }
    

Are there any other such annotations?

like image 660
Jean-Philippe Pellet Avatar asked Dec 10 '10 15:12

Jean-Philippe Pellet


3 Answers

There is @migration, which is used with -Xmigration to indicate semantic changes in methods from one version to another, in helping port code between versions.

@migration(2, 8, "As of 2.8, keys returns Iterable[A] rather than Iterator[A].")
like image 168
Daniel C. Sobral Avatar answered Nov 07 '22 05:11

Daniel C. Sobral


There is @tailrec, which makes the compiler output an error if tail call optimization cannot be applied to the annotated method.

like image 24
Kim Stebel Avatar answered Nov 07 '22 04:11

Kim Stebel


As of Scala 2.9, there's also @deprecatedName: “An annotation that designates the name of the parameter to which it is applied as deprecated. Using that name in a named argument generates a deprecation warning.”

like image 40
Jean-Philippe Pellet Avatar answered Nov 07 '22 05:11

Jean-Philippe Pellet