Introduce DeferredIsResultInspection #KT-25620 Fixed

This commit is contained in:
Mikhail Glukhikh
2018-11-23 18:09:25 +03:00
parent f4aad70b36
commit ca87e53f04
20 changed files with 440 additions and 161 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.coroutines.DeferredIsResultInspection
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Unwrap 'Deferred' return type (breaks use-sites!)
package kotlinx.coroutines
interface My {
fun <caret>function(): Deferred<Int>
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Unwrap 'Deferred' return type (breaks use-sites!)
package kotlinx.coroutines
interface My {
suspend fun <caret>function(): Int
}
@@ -0,0 +1,18 @@
// WITH_RUNTIME
// FIX: Add '.await()' to function result (breaks use-sites!)
package kotlinx.coroutines
// TODO: this test contains strange formatting bug (see 0 -> return in *.after file). To be fixed.
fun <caret>myFunction(context: CoroutineContext, switch: Int): Deferred<Int> {
with (GlobalScope) {
when (switch) {
0 -> return async {
val x = 123
x * x
}
1 -> return async(context) { -1 }
else -> return async() { 9 }
}
}
}
@@ -0,0 +1,18 @@
// WITH_RUNTIME
// FIX: Add '.await()' to function result (breaks use-sites!)
package kotlinx.coroutines
// TODO: this test contains strange formatting bug (see 0 -> return in *.after file). To be fixed.
suspend fun myFunction(context: CoroutineContext, switch: Int): Int {
with (GlobalScope) {
when (switch) {
0 -> return withContext(Dispatchers.Default) {
val x = 123
x * x
}
1 -> return withContext(context) { -1 }
else -> return withContext(Dispatchers.Default) { 9 }
}
}
}
@@ -0,0 +1,46 @@
package kotlinx.coroutines
interface Deferred<T> {
suspend fun await(): T
}
interface CoroutineContext
object Dispatchers {
object Default : CoroutineContext
}
enum class CoroutineStart {
DEFAULT,
LAZY,
ATOMIC,
UNDISPATCHED
}
interface CoroutineScope {
val coroutineContext: CoroutineContext get() = Dispatchers.Default
}
object GlobalScope : CoroutineScope
fun <T> CoroutineScope.async(
context: CoroutineContext = Dispatchers.Default,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> T
): Deferred<T> {
TODO()
}
suspend fun <T> withContext(
context: CoroutineContext,
block: suspend CoroutineScope.() -> T
): T {
TODO()
}
suspend fun <R> coroutineScope(block: suspend CoroutineScope.() -> R): R = GlobalScope.block()
operator fun CoroutineContext.plus(other: CoroutineContext): CoroutineContext {
TODO()
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Rename to 'myFunctionAsync'
package kotlinx.coroutines
fun <caret>myFunction(): Deferred<Int> {
return GlobalScope.async { 42 }
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Rename to 'myFunctionAsync'
package kotlinx.coroutines
fun myFunctionAsync(): Deferred<Int> {
return GlobalScope.async { 42 }
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Add '.await()' to function result (breaks use-sites!)
package kotlinx.coroutines
fun <caret>myFunction(): Deferred<Int> {
return GlobalScope.async { 42 }
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// FIX: Add '.await()' to function result (breaks use-sites!)
package kotlinx.coroutines
suspend fun myFunction(): Int {
return withContext(Dispatchers.Default) { 42 }
}
@@ -34,7 +34,7 @@ fun <T> CoroutineScope.async(
suspend fun <T> withContext(
context: CoroutineContext,
block: suspend CoroutineScope.() -> T
) {
): T {
TODO()
}