【问题标题】:system SBT not picking up type parameter in the code, Intellij sbt does系统 SBT 没有在代码中提取类型参数,Intellij sbt 可以
【发布时间】:2020-06-30 08:55:23
【问题描述】:

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

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

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

任何事情都会有帮助。

【问题讨论】:

    标签: scala intellij-idea sbt scala-cats


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2014-08-01
      • 2015-10-02
      • 1970-01-01
      • 1970-01-01
      • 2016-12-13
      • 2019-09-05
      • 2015-08-31
      • 2018-02-12
      • 2018-08-03
      相关资源
      最近更新 更多