Scala 类型失配;带有-Xstrict推断编译器选项的result.type(具有底层类型T)

Scala 类型失配;带有-Xstrict推断编译器选项的result.type(具有底层类型T),scala,Scala,我正在尝试用fold方法丰富scala.util.Try类型。我有以下几点要做: implicit class FoldableTry[T](tryable: Try[T]) { def fold[X](failure: Throwable => X)(success: T => X): X = { tryable match { case Success(result) => success(result) case Failure(ex)

我正在尝试用fold方法丰富
scala.util.Try
类型。我有以下几点要做:

implicit class FoldableTry[T](tryable: Try[T]) {
  def fold[X](failure: Throwable => X)(success: T => X): X = {
    tryable match {
      case Success(result) => success(result)
      case Failure(ex) => failure(ex)
    }
  }
}
当我使用-Xstrict推断编译器选项运行sbt compile时,我得到以下错误:

type mismatch;
[error]  found   : result.type (with underlying type T)
[error]  required: T
[error]         case Success(result) => success(result)
[error]                                         ^
[error] one error found
[error] (compile:compile) Compilation failed

如何修复此错误?如果我删除编译器标志,它将编译。

看起来您遇到了一个错误。我建议不要使用-Xstrict推断,因为它听起来像是实验性的,请注意Paul Phillip的评论:

-Xstrict推断只是一个粗略的开始,但它有点与我的离开相吻合。我预计它充满了执行问题


看来你是对的,史蒂夫。还有一些其他相关的bug:1。2.3.该建议反对使用该标志,因为它仍在开发中。