ghedeon
12/16/2019, 5:33 PMif
but fails otherwise.
Type mismatch error:
sealed class Foo
object Valid : Foo()
object Empty : Foo()
fun doSomething1(): Result<Foo> {
return Result.failure<Valid>(Exception()).recover { if (true) Empty else Valid }
}
Works fine:
fun doSomething2(): Result<Foo> {
return Result.failure<Valid>(Exception()).recover { Empty }
}
StavFX
12/16/2019, 6:41 PMResult.failure
that you will return Valid
, but then you return Empty
.
This should work (failure<Valid> replaced with failure<Foo>)
fun doSomething1(): Result<Foo> {
return Result.failure<Foo>(Exception())
.recover { if (true) Empty else Valid }
}
StavFX
12/16/2019, 6:46 PMResult<Foo>
/shrugghedeon
12/16/2019, 6:47 PMMike
12/16/2019, 9:19 PMreturn Result.failure(Exception())...
and the compiler would infer the return type correctly.StavFX
12/16/2019, 10:16 PMfun doSomething1(): Result<Foo> {
return Result.failure<Valid>(Exception())
.recover {
val temp = if (true) Empty else Valid
return@recover temp
}
}
If this works (just removed return@recover)
fun doSomething1(): Result<Foo> {
return Result.failure<Valid>(Exception())
.recover {
val temp = if (true) Empty else Valid
temp
}
}
ghedeon
12/17/2019, 10:06 AM-XXLanguage:+NewInference
.
https://youtrack.jetbrains.com/issue/KT-35514