我正在尝试使用 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-inference 编译器选项运行 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
如何解决这个错误?如果我删除它编译的编译器标志。
最佳答案
看起来您遇到了 bug (SI-6680) .我建议不要使用 -Xstrict-inference,因为它听起来很实验性——请注意 Paul Phillip 的评论:
-Xstrict-inference was intended only as a coarse hacky start, but it kind of coincided with my departure. I expect it is overflowing with implementation issues.
关于scala - 类型不匹配;带有 -Xstrict-inference 编译器选项的 result.type(具有底层类型 T),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31285475/