Introduce specific version of NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY for KT-28061
In 1.3.0 there was introduced KT-28061 bug, which caused some of the
NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY diagnostics to be lost (turning
"red" code into "green")
500dc11514 fixes the bug and returns
lost diagnostics back. This commit adds additional information for some
of the cases where diagnostics were list and then brought back (for the
user sanity).
The heuristic used for detecting cases which need additional information
is simple: if function has return in in-place called lambda, and
NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY should be reported, then we
enhance it with additional information.
^KT-28061 Fixed
This commit is contained in:
+9
-3
@@ -3,15 +3,21 @@
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
inline fun Any?.myRun(block: () -> Unit): Unit {
|
||||
inline fun <T> Any?.myRun(block: () -> T): T {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return block()
|
||||
}
|
||||
|
||||
fun test(): String {
|
||||
fun bad(): String {
|
||||
val x: String? = null
|
||||
|
||||
x?.myRun { return "" }
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY_MIGRATION!>}<!>
|
||||
|
||||
fun ok(): String {
|
||||
val x: String? = null
|
||||
|
||||
x?.run { return "non-null" } ?: return "null"
|
||||
}
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.String
|
||||
public inline fun kotlin.Any?.myRun(/*0*/ block: () -> kotlin.Unit): kotlin.Unit
|
||||
public fun bad(): kotlin.String
|
||||
public fun ok(): kotlin.String
|
||||
public inline fun </*0*/ T> kotlin.Any?.myRun(/*0*/ block: () -> T): T
|
||||
CallsInPlace(block, EXACTLY_ONCE)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user