Use lexical scope from trace during checking suspend context if the analysis of engaged parent function isn't completed

^KT-39461 Fixed
This commit is contained in:
Victor Petukhov
2020-06-16 17:20:54 +03:00
parent 02f6a03ff7
commit 901b794af3
8 changed files with 135 additions and 12 deletions
@@ -0,0 +1,39 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST -UNUSED_LAMBDA_EXPRESSION
class Foo {
suspend operator fun <T> invoke(body: suspend (Int) -> T) = null as T
suspend fun <T> bar(body: suspend (Int) -> T) = null as T
}
fun <T> runBlocking(block: suspend () -> T) = null as T
public inline fun <T, R> T.run(block: T.() -> R) = null as R
fun main() {
val retry = Foo()
runBlocking {
retry { 1 } // OK only after fix
}
runBlocking {
retry { 1 } // OK
1
}
runBlocking {
retry.bar { 1 } // OK
}
runBlocking {
{ retry { 1 } } // should be error
}
runBlocking {
10.run { retry { 1 } } // should be OK
}
runBlocking {
10.run { retry { 1 } } // should be OK
1
}
runBlocking {
{ retry { 1 } } // should be error
1
}
}
@@ -0,0 +1,39 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST -UNUSED_LAMBDA_EXPRESSION
class Foo {
suspend operator fun <T> invoke(body: suspend (Int) -> T) = null as T
suspend fun <T> bar(body: suspend (Int) -> T) = null as T
}
fun <T> runBlocking(block: suspend () -> T) = null as T
public inline fun <T, R> T.run(block: T.() -> R) = null as R
fun main() {
val retry = Foo()
runBlocking {
retry { 1 } // OK only after fix
}
runBlocking {
retry { 1 } // OK
1
}
runBlocking {
retry.bar { 1 } // OK
}
runBlocking {
{ <!NON_LOCAL_SUSPENSION_POINT!>retry<!> { 1 } } // should be error
}
runBlocking {
10.run { retry { 1 } } // should be OK
}
runBlocking {
10.run { retry { 1 } } // should be OK
1
}
runBlocking {
{ <!NON_LOCAL_SUSPENSION_POINT!>retry<!> { 1 } } // should be error
1
}
}
@@ -0,0 +1,14 @@
package
public fun main(): kotlin.Unit
public fun </*0*/ T> runBlocking(/*0*/ block: suspend () -> T): T
public inline fun </*0*/ T, /*1*/ R> T.run(/*0*/ block: T.() -> R): R
public final class Foo {
public constructor Foo()
public final suspend fun </*0*/ T> bar(/*0*/ body: suspend (kotlin.Int) -> T): T
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final suspend operator fun </*0*/ T> invoke(/*0*/ body: suspend (kotlin.Int) -> T): T
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}