Add inspection "Redundant runCatching {}" (related to KT-25621)

This commit is contained in:
Mikhail Glukhikh
2018-08-23 13:30:04 +03:00
parent 2084e94099
commit 7a2d0a3bb2
13 changed files with 153 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.coroutines.RedundantRunCatchingInspection
@@ -0,0 +1,11 @@
// WITH_RUNTIME
package kotlin
class SuccessOrFailure<T>(val value: T?) {
fun getOrThrow(): T = value ?: throw AssertionError("")
}
fun <T> runCatching(block: () -> T) = SuccessOrFailure(block())
fun correct(arg: Boolean) = runCatching<caret> { if (arg) throw AssertionError("") else 12 }.getOrThrow()
@@ -0,0 +1,11 @@
// WITH_RUNTIME
package kotlin
class SuccessOrFailure<T>(val value: T?) {
fun getOrThrow(): T = value ?: throw AssertionError("")
}
fun <T> runCatching(block: () -> T) = SuccessOrFailure(block())
fun correct(arg: Boolean) = run { if (arg) throw AssertionError("") else 12 }