Add inspection "Redundant runCatching {}" (related to KT-25621)
This commit is contained in:
@@ -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()
|
||||
+11
@@ -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 }
|
||||
Reference in New Issue
Block a user