Scala 隐式参数被编译器标记为未使用 [英] Scala implicit parameters are marked as unused by the compiler

查看:40
本文介绍了Scala 隐式参数被编译器标记为未使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 -Ywarn-unused 编译时,scala 中,隐式参数被标记为从不使用,即使它们在隐式作用域中使用.

In scala when compiling with -Ywarn-unused, implicit parameters are marked as never used even if they are used in implicit scope.

例如

class MyClass(implicit: ec: ExecutionContext) {
  def fun = Future.successful("hi").map(_.length)
}

这在使用 -Xfatal-warnings 运行时也是有问题的.

This is problematic when running with -Xfatal-warnings as well.

有没有办法提示编译器实际上使用了这些参数?如果没有,是否有另一种方法可以确保代码不会使用未使用的参数和声明进行编译?

Is there a way to hint to the compiler that these parameters are in fact used? If not, is there another way to ensure code won't compile with unused parameters and declarations?

推荐答案

使用 -Ywarn-macros:after flag 也是.它基本上告诉编译器在宏扩展之后进行未使用的检查,这通常可以解决未使用的隐式问题.

Use the -Ywarn-macros:after flag too. It basically tells the compiler to make the unused checks after macro expansion, that usually solve the problem of unused implicits.

这篇关于Scala 隐式参数被编译器标记为未使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆