Type mismatch; result.type (with base type T) with -Xstrict-inference compiler option
I am trying to enrich a type scala.util.Try
with the fold method. For this I have the following:
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)
}
}
}
When I run sbt compile with the -Xstrict-inference compiler option , I get the following error:
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
How can I fix this error? If I remove the compiler flag it compiles.
+3
source to share
1 answer
It looks like you are facing error (SI-6680) . I recommend against using -Xstrict-inference as it sounds experimental. Note the comment by Paul Phillip:
-Xstrict-inference was only intended as a rough hack start, but it somehow coincided with my departure. I expect it to be full of implementation problems.
+2
source to share