首页 > 解决方案 > 系统 SBT 没有在代码中提取类型参数,Intellij sbt 可以

问题描述

我有一段代码,其中我显式传递了一个类型参数,该参数由 intelliJ 很好地拾取,并且 intelliJ 没有指出错误,但是当我使用系统 sbt 编译相同的代码时,它不会拾取类型参数并与范围内的多个匹配隐式类型混淆。

intelliJ 中的代码没有错误标记:intelliJ 中的代码没有错误标记:

在系统 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

我是否以正确的方式看待问题?还是这是由其他原因引起的?

任何事情都会有所帮助。

标签: scalaintellij-ideasbtscala-cats

解决方案


使用 Scala 编译器的系统 sbt 比 IntelliJ Scala 编译器具有权威性。当两者不同意时,您应该选择前者。确保启用use sbt shell以最大程度地减少差异。请注意,即使use sbt shell启用了编辑器中的错误突出显示,也可能会产生误报,因为它使用了与 Scala 本身不同的进程。要考虑的替代方法是不应该有这种差异的金属。


推荐阅读