Report error on non-tail suspend-calls
It only concerns calls inside another suspend function #KT-14924 In Progress
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun nonSuspend() {}
|
||||
|
||||
suspend fun foo() {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>suspendWithCurrentContinuation { x: Continuation<Int> -> }<!>
|
||||
|
||||
nonSuspend()
|
||||
}
|
||||
|
||||
suspend fun unitSuspend() {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>suspendWithCurrentContinuation { x: Continuation<Int> -> }<!>
|
||||
}
|
||||
|
||||
suspend fun baz(): Int = run {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>suspendWithCurrentContinuation { x: Continuation<Int> -> }<!>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
public suspend fun baz(): kotlin.Int
|
||||
public suspend fun foo(): kotlin.Unit
|
||||
public fun nonSuspend(): kotlin.Unit
|
||||
public suspend fun unitSuspend(): kotlin.Unit
|
||||
@@ -0,0 +1,17 @@
|
||||
suspend fun baz() = 1
|
||||
suspend fun unit() {}
|
||||
|
||||
suspend fun foo() {
|
||||
suspend fun bar() {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE, SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>baz()<!>
|
||||
return unit()
|
||||
}
|
||||
|
||||
suspend fun foobar1(): Int {
|
||||
return baz()
|
||||
}
|
||||
|
||||
suspend fun foobar2() {
|
||||
return unit()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package
|
||||
|
||||
public suspend fun baz(): kotlin.Int
|
||||
public suspend fun foo(): kotlin.Unit
|
||||
public suspend fun unit(): kotlin.Unit
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// Tail calls are not allowed to be Nothing typed. See KT-15051
|
||||
suspend fun suspendLogAndThrow(exception: Throwable): Nothing = <!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>suspendWithCurrentContinuation { c ->
|
||||
c.resumeWithException(exception)
|
||||
Suspend
|
||||
}<!>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public suspend fun suspendLogAndThrow(/*0*/ exception: kotlin.Throwable): kotlin.Nothing
|
||||
@@ -0,0 +1,18 @@
|
||||
suspend fun unit1() {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>unit1()<!>
|
||||
}
|
||||
|
||||
suspend fun unit2() {
|
||||
return unit2()
|
||||
}
|
||||
|
||||
suspend fun int1(): Int {
|
||||
return int1()
|
||||
}
|
||||
|
||||
suspend fun int2(): Int = int2()
|
||||
|
||||
suspend fun int3(): Int {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>int3()<!>
|
||||
return int3()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
public suspend fun int1(): kotlin.Int
|
||||
public suspend fun int2(): kotlin.Int
|
||||
public suspend fun int3(): kotlin.Int
|
||||
public suspend fun unit1(): kotlin.Unit
|
||||
public suspend fun unit2(): kotlin.Unit
|
||||
@@ -0,0 +1,39 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
fun nonSuspend() {}
|
||||
|
||||
suspend fun baz(): Int = 1
|
||||
|
||||
suspend fun tryCatch(): Int {
|
||||
return try {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>suspendWithCurrentContinuation { x: Continuation<Int> -> }<!>
|
||||
} catch (e: Exception) {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>baz()<!> // another suspend function
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun tryFinally(): Int {
|
||||
return try {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>suspendWithCurrentContinuation { x: Continuation<Int> -> }<!>
|
||||
} finally {
|
||||
nonSuspend()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun returnInFinally(): Int {
|
||||
try {
|
||||
} finally {
|
||||
// Probably this is too restrictive, but it does not matter much
|
||||
return <!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE, SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>baz()<!>
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun tryCatchFinally(): Int {
|
||||
return try {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>suspendWithCurrentContinuation { x: Continuation<Int> -> }<!>
|
||||
} catch (e: Exception) {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>baz()<!> // another suspend function
|
||||
} finally {
|
||||
<!SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE, SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE!>baz()<!>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package
|
||||
|
||||
public suspend fun baz(): kotlin.Int
|
||||
public fun nonSuspend(): kotlin.Unit
|
||||
public suspend fun returnInFinally(): kotlin.Int
|
||||
public suspend fun tryCatch(): kotlin.Int
|
||||
public suspend fun tryCatchFinally(): kotlin.Int
|
||||
public suspend fun tryFinally(): kotlin.Int
|
||||
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
suspend fun baz() = 1
|
||||
|
||||
suspend fun foo() {}
|
||||
|
||||
suspend fun bar0() = baz()
|
||||
suspend fun bar01(): Int {
|
||||
return baz()
|
||||
}
|
||||
|
||||
suspend fun bar1() {
|
||||
return if (1.hashCode() > 0) {
|
||||
foo()
|
||||
}
|
||||
else suspendWithCurrentContinuation { x: Continuation<Unit> -> }
|
||||
}
|
||||
|
||||
suspend fun bar2() =
|
||||
if (1.hashCode() > 0) {
|
||||
foo()
|
||||
}
|
||||
else suspendWithCurrentContinuation { x: Continuation<Unit> -> }
|
||||
|
||||
suspend fun bar3() =
|
||||
when {
|
||||
true -> { foo() }
|
||||
else -> suspendWithCurrentContinuation { x: Continuation<Unit> -> }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
public suspend fun bar0(): kotlin.Int
|
||||
public suspend fun bar01(): kotlin.Int
|
||||
public suspend fun bar1(): kotlin.Unit
|
||||
public suspend fun bar2(): kotlin.Unit
|
||||
public suspend fun bar3(): kotlin.Unit
|
||||
public suspend fun baz(): kotlin.Int
|
||||
public suspend fun foo(): kotlin.Unit
|
||||
Reference in New Issue
Block a user