Rename SuccessOrFailure to Result and hide Failure from ABI
* The members of Result are isSuccess, isFailure, exceptionOrNull, getOrNull * The rest of API is implemented via inline-only extensions * There are two internal functions to hide detailed mechanics of an internal Result.Failure class: createFailure and throwOnFailure * Result.toString is explicit: either Success(v) or Failure(x) See KT-26538
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<body>
|
||||
This inspection reports functions with <b>Result</b> result.
|
||||
|
||||
<b>Result</b> should never be used as return type.
|
||||
Throw exception, or use nullable type, or use domain-specific result class to indicate failure.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,8 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
This inspection reports functions with <b>SuccessOrFailure</b> result.
|
||||
|
||||
<b>SuccessOrFailure</b> should never be used as return type.
|
||||
Throw exception, or use nullable type, or use domain-specific result class to indicate failure.
|
||||
</body>
|
||||
</html>
|
||||
@@ -3021,8 +3021,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection"
|
||||
displayName="Function returning SuccessOrFailure"
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection"
|
||||
displayName="Function returning Result"
|
||||
groupPath="Kotlin"
|
||||
groupName="Style issues"
|
||||
enabledByDefault="true"
|
||||
|
||||
@@ -3019,8 +3019,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection"
|
||||
displayName="Function returning SuccessOrFailure"
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection"
|
||||
displayName="Function returning Result"
|
||||
groupPath="Kotlin"
|
||||
groupName="Style issues"
|
||||
enabledByDefault="true"
|
||||
|
||||
@@ -3020,8 +3020,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection"
|
||||
displayName="Function returning SuccessOrFailure"
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection"
|
||||
displayName="Function returning Result"
|
||||
groupPath="Kotlin"
|
||||
groupName="Style issues"
|
||||
enabledByDefault="true"
|
||||
|
||||
@@ -3021,8 +3021,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection"
|
||||
displayName="Function returning SuccessOrFailure"
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection"
|
||||
displayName="Function returning Result"
|
||||
groupPath="Kotlin"
|
||||
groupName="Style issues"
|
||||
enabledByDefault="true"
|
||||
|
||||
@@ -3019,8 +3019,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection"
|
||||
displayName="Function returning SuccessOrFailure"
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection"
|
||||
displayName="Function returning Result"
|
||||
groupPath="Kotlin"
|
||||
groupName="Style issues"
|
||||
enabledByDefault="true"
|
||||
|
||||
@@ -3019,8 +3019,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection"
|
||||
displayName="Function returning SuccessOrFailure"
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection"
|
||||
displayName="Function returning Result"
|
||||
groupPath="Kotlin"
|
||||
groupName="Style issues"
|
||||
enabledByDefault="true"
|
||||
|
||||
@@ -3021,8 +3021,8 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
||||
language="kotlin"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection"
|
||||
displayName="Function returning SuccessOrFailure"
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection"
|
||||
displayName="Function returning Result"
|
||||
groupPath="Kotlin"
|
||||
groupName="Style issues"
|
||||
enabledByDefault="true"
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class RedundantRunCatchingInspection : AbstractCallChainChecker() {
|
||||
private val conversions = listOf(
|
||||
Conversion(
|
||||
"kotlin.runCatching",
|
||||
"kotlin.SuccessOrFailure.getOrThrow",
|
||||
"kotlin.Result.getOrThrow",
|
||||
"run"
|
||||
)
|
||||
)
|
||||
|
||||
+4
-4
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class ResultIsSuccessOrFailureInspection : AbstractKotlinInspection() {
|
||||
class ResultIsResultInspection : AbstractKotlinInspection() {
|
||||
|
||||
private fun MemberScope.hasCorrespondingNonCatchingFunction(
|
||||
nameWithoutCatching: String,
|
||||
@@ -85,13 +85,13 @@ class ResultIsSuccessOrFailureInspection : AbstractKotlinInspection() {
|
||||
if (name in ALLOWED_NAMES) return
|
||||
if (function is KtNamedFunction) {
|
||||
val receiverTypeReference = function.receiverTypeReference
|
||||
// Filter SuccessOrFailure extensions
|
||||
// Filter Result extensions
|
||||
if (receiverTypeReference != null && SHORT_NAME in receiverTypeReference.text) return
|
||||
}
|
||||
if (function is KtFunctionLiteral || returnTypeText == null) {
|
||||
// Heuristics to save performance
|
||||
val text = function.bodyExpression?.text
|
||||
// Check there is something creating SuccessOrFailure in function text
|
||||
// Check there is something creating Result in function text
|
||||
if (text != null && ALLOWED_NAMES.none { it in text } && SHORT_NAME !in text && CATCHING !in text) return
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ class ResultIsSuccessOrFailureInspection : AbstractKotlinInspection() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val SHORT_NAME = "SuccessOrFailure"
|
||||
private const val SHORT_NAME = "Result"
|
||||
|
||||
private const val FULL_NAME = "kotlin.$SHORT_NAME"
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: SuccessOrFailure<Any?>) { result.getOrThrow() }
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
|
||||
|
||||
+24
-24
@@ -5,8 +5,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function returning Result with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -14,8 +14,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function returning Result with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -23,8 +23,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function 'incorrectCatching' returning 'SuccessOrFailure<Double>' without the corresponding function 'incorrect' returning 'Double'</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function 'incorrectCatching' returning 'Result<Double>' without the corresponding function 'incorrect' returning 'Double'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -32,8 +32,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function 'strangeCatching' returning 'SuccessOrFailure<Boolean>' without the corresponding function 'strange' returning 'Boolean'</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function 'strangeCatching' returning 'Result<Boolean>' without the corresponding function 'strange' returning 'Boolean'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -41,8 +41,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function returning Result with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -50,8 +50,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function returning Result with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -59,8 +59,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function 'classIncorrectCatching' returning 'SuccessOrFailure<Double>' without the corresponding function 'classIncorrect' returning 'Double'</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function 'classIncorrectCatching' returning 'Result<Double>' without the corresponding function 'classIncorrect' returning 'Double'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -68,8 +68,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function returning Result with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -77,8 +77,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function returning Result with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -86,8 +86,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function returning SuccessOrFailure with a name that does not end with Catching</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function returning Result with a name that does not end with Catching</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -95,8 +95,8 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function 'calcComplexCatching' returning 'SuccessOrFailure<Double>' without the corresponding function 'calcComplex' returning 'Double'</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function 'calcComplexCatching' returning 'Result<Double>' without the corresponding function 'calcComplex' returning 'Double'</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>test.kt</file>
|
||||
@@ -104,7 +104,7 @@
|
||||
<module>light_idea_test_case</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="temp:///src/test.kt" />
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning SuccessOrFailure</problem_class>
|
||||
<description>Function 'extensionActCatching' returning 'SuccessOrFailure<Int>' without the corresponding function 'extensionAct' returning 'Int'</description>
|
||||
<problem_class severity="WEAK WARNING" attribute_key="INFO_ATTRIBUTES">Function returning Result</problem_class>
|
||||
<description>Function 'extensionActCatching' returning 'Result<Int>' without the corresponding function 'extensionAct' returning 'Int'</description>
|
||||
</problem>
|
||||
</problems>
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection
|
||||
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
package kotlin
|
||||
// NO (constructor)
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
// YES
|
||||
fun getSuccess() = success()
|
||||
// YES
|
||||
fun getSuccessExplicit(): SuccessOrFailure<Int> = SuccessOrFailure(456)
|
||||
fun getSuccessExplicit(): Result<Int> = Result(456)
|
||||
// NO (not catching 'correct' available)
|
||||
fun correctCatching() = SuccessOrFailure(true)
|
||||
// NO (not SuccessOrFailure)
|
||||
fun correctCatching() = Result(true)
|
||||
// NO (not Result)
|
||||
fun correct() = true
|
||||
// YES
|
||||
fun incorrectCatching() = SuccessOrFailure(3.14)
|
||||
fun incorrectCatching() = Result(3.14)
|
||||
// YES
|
||||
fun strangeCatching() = runCatching { false }
|
||||
// NO (not SuccessOrFailure)
|
||||
// NO (not Result)
|
||||
fun strange() = 1
|
||||
|
||||
class Container {
|
||||
// YES
|
||||
fun classGetSuccess() = SuccessOrFailure("123")
|
||||
fun classGetSuccess() = Result("123")
|
||||
// YES
|
||||
fun classGetSuccessExplicit(): SuccessOrFailure<Int> = SuccessOrFailure(456)
|
||||
fun classGetSuccessExplicit(): Result<Int> = Result(456)
|
||||
// NO (not catching 'classCorrect' available)
|
||||
fun classCorrectCatching() = SuccessOrFailure(true)
|
||||
// NO (not SuccessOrFailure)
|
||||
fun classCorrectCatching() = Result(true)
|
||||
// NO (not Result)
|
||||
fun classCorrect() = true
|
||||
// YES
|
||||
fun classIncorrectCatching() = SuccessOrFailure(3.14)
|
||||
fun classIncorrectCatching() = Result(3.14)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
// YES
|
||||
fun localGetSuccess() = SuccessOrFailure("123")
|
||||
fun localGetSuccess() = Result("123")
|
||||
// YES
|
||||
val anonymous = fun() = SuccessOrFailure(45)
|
||||
val anonymous = fun() = Result(45)
|
||||
// YES
|
||||
val lambda = { SuccessOrFailure(true) }
|
||||
val lambda = { Result(true) }
|
||||
// NO yet (we do not report local *catching functions)
|
||||
fun localCatching() = SuccessOrFailure(2.72)
|
||||
fun localCatching() = Result(2.72)
|
||||
}
|
||||
|
||||
// NO (stdlib)
|
||||
fun success() = SuccessOrFailure(true)
|
||||
fun success() = Result(true)
|
||||
// NO (stdlib)
|
||||
fun failure() = SuccessOrFailure(false)
|
||||
fun failure() = Result(false)
|
||||
// NO (stdlib)
|
||||
fun <T> runCatching(block: () -> T) = SuccessOrFailure(block())
|
||||
fun <T> runCatching(block: () -> T) = Result(block())
|
||||
// NO (stdlib)
|
||||
fun <T> SuccessOrFailure<T>.id() = this
|
||||
fun <T> Result<T>.id() = this
|
||||
|
||||
class ClassWithExtension() {
|
||||
// NO (not SuccessOrFailure)
|
||||
// NO (not Result)
|
||||
fun calc() = 12345
|
||||
// NO (not SuccessOrFailure)
|
||||
// NO (not Result)
|
||||
fun calcComplex(arg1: Int, arg2: Double): Double = arg1 + arg2
|
||||
// YES (different parameters)
|
||||
fun calcComplexCatching() = SuccessOrFailure(0.0)
|
||||
fun calcComplexCatching() = Result(0.0)
|
||||
}
|
||||
// NO (extension to calc)
|
||||
fun ClassWithExtension.calcCatching() = SuccessOrFailure(calc())
|
||||
// NO (not SuccessOrFailure)
|
||||
fun ClassWithExtension.calcCatching() = Result(calc())
|
||||
// NO (not Result)
|
||||
fun Container.extensionAct() = 42
|
||||
// YES (different extension receiver)
|
||||
fun ClassWithExtension.extensionActCatching() = SuccessOrFailure(42)
|
||||
fun ClassWithExtension.extensionActCatching() = Result(42)
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun <T> runCatching(block: () -> T) = SuccessOrFailure(block())
|
||||
fun <T> runCatching(block: () -> T) = Result(block())
|
||||
|
||||
fun correct(arg: Boolean) = runCatching<caret> { if (arg) throw AssertionError("") else 12 }.getOrThrow()
|
||||
|
||||
+2
-2
@@ -2,10 +2,10 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun <T> runCatching(block: () -> T) = SuccessOrFailure(block())
|
||||
fun <T> runCatching(block: () -> T) = Result(block())
|
||||
|
||||
fun correct(arg: Boolean) = run { if (arg) throw AssertionError("") else 12 }
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsSuccessOrFailureInspection
|
||||
org.jetbrains.kotlin.idea.inspections.coroutines.ResultIsResultInspection
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
// FIX: Unwrap 'SuccessOrFailure' return type (breaks use-sites!)
|
||||
// FIX: Unwrap 'Result' return type (breaks use-sites!)
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
abstract class Abstract {
|
||||
abstract fun <caret>foo(): SuccessOrFailure<Int>
|
||||
abstract fun <caret>foo(): Result<Int>
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// FIX: Unwrap 'SuccessOrFailure' return type (breaks use-sites!)
|
||||
// FIX: Unwrap 'Result' return type (breaks use-sites!)
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val x = <caret>fun() = SuccessOrFailure("123")
|
||||
val x = <caret>fun() = Result("123")
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val x = fun() = SuccessOrFailure("123").getOrThrow()
|
||||
val x = fun() = Result("123").getOrThrow()
|
||||
}
|
||||
|
||||
+11
-11
@@ -3,28 +3,28 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun <caret>incorrectBlock(arg: Boolean, arg2: Boolean?): SuccessOrFailure<Int> {
|
||||
fun <caret>incorrectBlock(arg: Boolean, arg2: Boolean?): Result<Int> {
|
||||
if (arg) {
|
||||
class Local {
|
||||
fun foo(): SuccessOrFailure<String> {
|
||||
return SuccessOrFailure("NO")
|
||||
fun foo(): Result<String> {
|
||||
return Result("NO")
|
||||
}
|
||||
}
|
||||
return SuccessOrFailure(1)
|
||||
return Result(1)
|
||||
} else {
|
||||
when (arg2) {
|
||||
true -> {
|
||||
val x = fun(): SuccessOrFailure<Boolean> {
|
||||
return SuccessOrFailure(false)
|
||||
val x = fun(): Result<Boolean> {
|
||||
return Result(false)
|
||||
}
|
||||
if (x().getOrThrow()) {
|
||||
return SuccessOrFailure(2)
|
||||
return Result(2)
|
||||
} else {
|
||||
return SuccessOrFailure(0)
|
||||
return Result(0)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -32,9 +32,9 @@ fun <caret>incorrectBlock(arg: Boolean, arg2: Boolean?): SuccessOrFailure<Int> {
|
||||
listOf(1, 2, 3).forEach {
|
||||
if (it == 2) return@forEach
|
||||
}
|
||||
return SuccessOrFailure(3)
|
||||
return Result(3)
|
||||
}
|
||||
return SuccessOrFailure(4)
|
||||
return Result(4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -3,28 +3,28 @@
|
||||
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun incorrectBlock(arg: Boolean, arg2: Boolean?): Int {
|
||||
if (arg) {
|
||||
class Local {
|
||||
fun foo(): SuccessOrFailure<String> {
|
||||
return SuccessOrFailure("NO")
|
||||
fun foo(): Result<String> {
|
||||
return Result("NO")
|
||||
}
|
||||
}
|
||||
return SuccessOrFailure(1).getOrThrow()
|
||||
return Result(1).getOrThrow()
|
||||
} else {
|
||||
when (arg2) {
|
||||
true -> {
|
||||
val x = fun(): SuccessOrFailure<Boolean> {
|
||||
return SuccessOrFailure(false)
|
||||
val x = fun(): Result<Boolean> {
|
||||
return Result(false)
|
||||
}
|
||||
if (x().getOrThrow()) {
|
||||
return SuccessOrFailure(2).getOrThrow()
|
||||
return Result(2).getOrThrow()
|
||||
} else {
|
||||
return SuccessOrFailure(0).getOrThrow()
|
||||
return Result(0).getOrThrow()
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
@@ -32,9 +32,9 @@ fun incorrectBlock(arg: Boolean, arg2: Boolean?): Int {
|
||||
listOf(1, 2, 3).forEach {
|
||||
if (it == 2) return@forEach
|
||||
}
|
||||
return SuccessOrFailure(3).getOrThrow()
|
||||
return Result(3).getOrThrow()
|
||||
}
|
||||
return SuccessOrFailure(4).getOrThrow()
|
||||
return Result(4).getOrThrow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val x = <caret>{ SuccessOrFailure(true) }
|
||||
val x = <caret>{ Result(true) }
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val x = { SuccessOrFailure(true).getOrThrow() }
|
||||
val x = { Result(true).getOrThrow() }
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -1,15 +1,15 @@
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun test(arg: Boolean) {
|
||||
val x = foo@<caret>{
|
||||
if (!arg) {
|
||||
return@foo SuccessOrFailure(true)
|
||||
return@foo Result(true)
|
||||
} else {
|
||||
SuccessOrFailure(false)
|
||||
Result(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -1,15 +1,15 @@
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun test(arg: Boolean) {
|
||||
val x = foo@{
|
||||
(if (!arg) {
|
||||
return@foo SuccessOrFailure(true).getOrThrow()
|
||||
return@foo Result(true).getOrThrow()
|
||||
} else {
|
||||
SuccessOrFailure(false)
|
||||
Result(false)
|
||||
}).getOrThrow()
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val x = foo@<caret>{ return@foo SuccessOrFailure(true) }
|
||||
val x = foo@<caret>{ return@foo Result(true) }
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,9 +1,9 @@
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val x = foo@<caret>{ return@foo SuccessOrFailure(true).getOrThrow() }
|
||||
val x = foo@<caret>{ return@foo Result(true).getOrThrow() }
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
// FIX: Add '.getOrThrow()' to function result (breaks use-sites!)
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
|
||||
operator fun plus(other: SuccessOrFailure<T>) = other
|
||||
operator fun plus(other: Result<T>) = other
|
||||
}
|
||||
|
||||
fun <caret>incorrect() = SuccessOrFailure("123") + SuccessOrFailure("456")
|
||||
fun <caret>incorrect() = Result("123") + Result("456")
|
||||
|
||||
Vendored
+3
-3
@@ -1,10 +1,10 @@
|
||||
// FIX: Add '.getOrThrow()' to function result (breaks use-sites!)
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
|
||||
operator fun plus(other: SuccessOrFailure<T>) = other
|
||||
operator fun plus(other: Result<T>) = other
|
||||
}
|
||||
|
||||
fun incorrect() = (SuccessOrFailure("123") + SuccessOrFailure("456")).getOrThrow()
|
||||
fun incorrect() = (Result("123") + Result("456")).getOrThrow()
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// FIX: Rename to 'incorrectCatching'
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun <caret>incorrect() = SuccessOrFailure("123")
|
||||
fun <caret>incorrect() = Result("123")
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// FIX: Rename to 'incorrectCatching'
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun <caret>incorrectCatching() = SuccessOrFailure("123")
|
||||
fun <caret>incorrectCatching() = Result("123")
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// FIX: Add '.getOrThrow()' to function result (breaks use-sites!)
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun <caret>incorrect() = SuccessOrFailure("123")
|
||||
fun <caret>incorrect() = Result("123")
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// FIX: Add '.getOrThrow()' to function result (breaks use-sites!)
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun incorrect() = SuccessOrFailure("123").getOrThrow()
|
||||
fun incorrect() = Result("123").getOrThrow()
|
||||
|
||||
+6
-6
@@ -1,21 +1,21 @@
|
||||
// FIX: Add '.getOrThrow()' to function result (breaks use-sites!)
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun <caret>incorrectBlock(arg: Boolean, arg2: Boolean?): SuccessOrFailure<Int> {
|
||||
fun <caret>incorrectBlock(arg: Boolean, arg2: Boolean?): Result<Int> {
|
||||
if (arg) {
|
||||
return SuccessOrFailure(1)
|
||||
return Result(1)
|
||||
} else {
|
||||
when (arg2) {
|
||||
true -> return SuccessOrFailure(2)
|
||||
true -> return Result(2)
|
||||
else -> {
|
||||
if (arg2 == false) {
|
||||
return SuccessOrFailure(3)
|
||||
return Result(3)
|
||||
}
|
||||
return SuccessOrFailure(4)
|
||||
return Result(4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,21 +1,21 @@
|
||||
// FIX: Add '.getOrThrow()' to function result (breaks use-sites!)
|
||||
package kotlin
|
||||
|
||||
class SuccessOrFailure<T>(val value: T?) {
|
||||
class Result<T>(val value: T?) {
|
||||
fun getOrThrow(): T = value ?: throw AssertionError("")
|
||||
}
|
||||
|
||||
fun incorrectBlock(arg: Boolean, arg2: Boolean?): Int {
|
||||
if (arg) {
|
||||
return SuccessOrFailure(1).getOrThrow()
|
||||
return Result(1).getOrThrow()
|
||||
} else {
|
||||
when (arg2) {
|
||||
true -> return SuccessOrFailure(2).getOrThrow()
|
||||
true -> return Result(2).getOrThrow()
|
||||
else -> {
|
||||
if (arg2 == false) {
|
||||
return SuccessOrFailure(3).getOrThrow()
|
||||
return Result(3).getOrThrow()
|
||||
}
|
||||
return SuccessOrFailure(4).getOrThrow()
|
||||
return Result(4).getOrThrow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user