开发者

What Scala annotations modify the compiler's messages?

开发者 https://www.devze.com 2023-01-30 12:15 出处:网络
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 i开发者_如何学运维n client code.

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 i开发者_如何学运维n 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?


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].")


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


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.”

0

精彩评论

暂无评论...
验证码 换一张
取 消