scala - 系统 SBT 没有在代码中提取类型参数,Intellij sbt 可以
问题描述
我有一段代码,其中我显式传递了一个类型参数,该参数由 intelliJ 很好地拾取,并且 intelliJ 没有指出错误,但是当我使用系统 sbt 编译相同的代码时,它不会拾取类型参数并与范围内的多个匹配隐式类型混淆。
在系统 sbt 上编译时的错误堆栈:
[error] one error found
[error] /Users/xxxxxx/projects/xxxxx-xxxxxx-xxxxxx/xxxxxxxxx/src/main/scala/com/xxxxxxx/Main.scala:93:33: ambiguous implicit values:
[error] both lazy value AsyncBlobIO in trait Instances of type => cats.effect.Async[doobie.free.BlobIO]
[error] and lazy value AsyncCallableStatementIO in trait Instances of type => cats.effect.Async[doobie.free.CallableStatementIO]
[error] match expected type cats.effect.Sync[F]
[error] result <- jobPaths(Paths.get(record.path), settings.baseFolder).use(paths => ingestionJob(record, paths))
[error] ^
如您所见,系统 sbt 不选择类型参数jobPaths[IO](..)
,而是jobPaths(..)
出于某种原因而运行。
JobPaths
功能定义如果有帮助:
def runJob[F[_]](
settings: Settings,
now: Instant,
consulSessionName: String,
assignerConfig: PartitionKeyAssignerConfig
)(implicit F: ConcurrentEffect[F], p: Parallel[F]): F[Unit] = {
系统 sbt 版本:
[info] 1.2.8
sbt script version: 1.3.12
我是否以正确的方式看待问题?还是这是由其他原因引起的?
任何事情都会有所帮助。
解决方案
使用 Scala 编译器的系统 sbt 比 IntelliJ Scala 编译器具有权威性。当两者不同意时,您应该选择前者。确保启用use sbt shell
以最大程度地减少差异。请注意,即使use sbt shell
启用了编辑器中的错误突出显示,也可能会产生误报,因为它使用了与 Scala 本身不同的进程。要考虑的替代方法是不应该有这种差异的金属。
推荐阅读
- android - Zsh:尝试运行 android-studio 模拟器时权限被拒绝
- c - 错误无法从我的链表中读取内存
- c# - 我可以用 Web api 控制器的传统路由模式替换属性路由吗?
- javascript - 如何通过 onSubmit 事件处理程序提交表单
- reactjs - 如何根据操作的结果重定向到路线
- reactjs - 使用 react-testing-library 测试 useQuery
- powershell - 从数组中检索项目总是返回 -1
- javascript - 如何在具有特定样式的 Javascript 数组中查找 HTML 元素?
- c - Linux如何检查list_head是否为空?
- java - 比较本地日期和本地时间