什么Scala注释修改编译器的消息?

Jea*_*let 17 annotations scala compiler-errors compiler-warnings

我知道两个:

  • @deprecated("use blabla instead") 用于在客户端代码中使用带注释的定义时,编译器向警告输出添加解释.
  • @implicitNotFound(msg = "more meaningful explanation")用于在无法找到带注释的定义类型的隐式时输出其他错误消息.看一下CanBuildFrom,msg可以包含类型的占位符${A}if if A是带注释类型的类型参数的名称,由编译器填充实际预期类型,例如:

    @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] { ... }
    
    Run Code Online (Sandbox Code Playgroud)

还有其他这样的注释吗?

Dan*_*ral 6

@migration一个用于-Xmigration指示方法从一个版本到另一个版本的语义变化,以帮助版本之间的端口代码.

@migration(2, 8, "As of 2.8, keys returns Iterable[A] rather than Iterator[A].")
Run Code Online (Sandbox Code Playgroud)


Kim*_*bel 6

有@tailrec,如果尾调用优化不能应用于带注释的方法,则会使编译器输出错误.