[Tests] Migrate backend-independent tests from native to compiler/testData.
^KT-65979
This commit is contained in:
committed by
Space Team
parent
dd9332d9e1
commit
febac0dd5f
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
interface I {
|
||||
suspend fun foo(lambda: suspend (String) -> Unit)
|
||||
suspend fun bar(s: String)
|
||||
}
|
||||
|
||||
fun create() = object: I {
|
||||
var lambda: suspend (String) -> Unit = {}
|
||||
|
||||
override suspend fun foo(lambda: suspend (String) -> Unit) {
|
||||
this.lambda = lambda
|
||||
}
|
||||
|
||||
override suspend fun bar(s: String) {
|
||||
lambda(s)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
builder {
|
||||
val z = create()
|
||||
z.foo { suspendHere(); sb.append(it) }
|
||||
z.bar("zzz")
|
||||
}
|
||||
assertEquals("zzz", sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
// See https://github.com/JetBrains/kotlin-native/issues/3476
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
builder {
|
||||
foo().bar()
|
||||
result = 1
|
||||
}
|
||||
assertEquals(1, result)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
class Foo {
|
||||
suspend fun bar() {
|
||||
suspendHere()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun foo() = Foo()
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_finally1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = try {
|
||||
f1()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
} finally {
|
||||
s1()
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
assertEquals("""
|
||||
f1
|
||||
s1
|
||||
117
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_finally2Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
val x = try {
|
||||
f1()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
} finally {
|
||||
s1()
|
||||
}
|
||||
result = x
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
f1
|
||||
s1
|
||||
117
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_finally3Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
try {
|
||||
result = f1()
|
||||
} catch (t: Throwable) {
|
||||
result = f2()
|
||||
} finally {
|
||||
s1()
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
f1
|
||||
s1
|
||||
117
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_finally4Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
try {
|
||||
result = s1()
|
||||
} catch (t: Throwable) {
|
||||
result = f2()
|
||||
} finally {
|
||||
sb.appendLine("finally")
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s1
|
||||
finally
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_finally5Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resumeWithException(Error())
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
try {
|
||||
result = s1()
|
||||
} catch (t: Throwable) {
|
||||
result = f2()
|
||||
} finally {
|
||||
sb.appendLine("finally")
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s1
|
||||
f2
|
||||
finally
|
||||
1
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_finally6Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resumeWithException(Error("error"))
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
try {
|
||||
try {
|
||||
result = s1()
|
||||
} catch (t: ClassCastException) {
|
||||
result = f2()
|
||||
} finally {
|
||||
sb.appendLine("finally")
|
||||
}
|
||||
}
|
||||
catch(t: Error) {
|
||||
sb.appendLine(t.message)
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s1
|
||||
finally
|
||||
error
|
||||
0
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_finally7Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resumeWithException(Error())
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s2")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
try {
|
||||
try {
|
||||
result = s1()
|
||||
} catch (t: Throwable) {
|
||||
result = f2()
|
||||
} finally {
|
||||
sb.appendLine("finally1")
|
||||
result = s2()
|
||||
}
|
||||
} finally {
|
||||
sb.appendLine("finally2")
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s1
|
||||
f2
|
||||
finally1
|
||||
s2
|
||||
finally2
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_if1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = f3(if (f1() > 100) s1() else f2(), 42)
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
f1
|
||||
s1
|
||||
f3
|
||||
84
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_if2Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
if (f1() > 100)
|
||||
result = s1() + f2()
|
||||
else
|
||||
result = 42
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
f1
|
||||
s1
|
||||
f2
|
||||
43
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_inline1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
inline suspend fun inline_s2(): Int {
|
||||
return 42
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = inline_s2()
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("42\n", sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_inline2Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
inline suspend fun inline_s2(): Int {
|
||||
var x = s1()
|
||||
return x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = inline_s2()
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s1
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_inline3Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
inline suspend fun inline_s2(): Int {
|
||||
var x = 0
|
||||
if (f1() > 0)
|
||||
x = s1()
|
||||
else x = f2()
|
||||
return x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = inline_s2()
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
f1
|
||||
s1
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_tryCatch1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
val x = try {
|
||||
s1()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
}
|
||||
result = x
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s1
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_tryCatch2Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = try {
|
||||
s1()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s1
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_tryCatch3Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s2")
|
||||
x.resumeWithException(Error())
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = try {
|
||||
s2()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s2
|
||||
f2
|
||||
1
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_tryCatch4Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s2")
|
||||
x.resumeWithException(Error())
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
val x = try {
|
||||
s2()
|
||||
} catch (t: Throwable) {
|
||||
f2()
|
||||
}
|
||||
result = x
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s2
|
||||
f2
|
||||
1
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_tryCatch5Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s2")
|
||||
x.resumeWithException(Error("Error"))
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = try {
|
||||
s2()
|
||||
} catch (t: Throwable) {
|
||||
val x = s1()
|
||||
sb.appendLine(t.message)
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s2
|
||||
s1
|
||||
Error
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_while1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s2")
|
||||
x.resumeWithException(Error("Error"))
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s3(value: Int): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s3")
|
||||
x.resume(value)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
while (s3(result) < 3)
|
||||
++result
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s3
|
||||
s3
|
||||
s3
|
||||
s3
|
||||
3
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ControlFlow_while2Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s2")
|
||||
x.resumeWithException(Error("Error"))
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s3(value: Int): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s3")
|
||||
x.resume(value)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun f3(x: Int, y: Int): Int {
|
||||
sb.appendLine("f3")
|
||||
return x + y
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
while (result < 3)
|
||||
result = s3(result) + 1
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
s3
|
||||
s3
|
||||
s3
|
||||
3
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS CoroutineContext1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
builder { sb.appendLine(coroutineContext) }
|
||||
|
||||
assertEquals("""
|
||||
EmptyCoroutineContext
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS CoroutineContext2Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
suspend fun foo() = coroutineContext
|
||||
|
||||
fun box(): String {
|
||||
builder { sb.appendLine(foo()) }
|
||||
|
||||
assertEquals("""
|
||||
EmptyCoroutineContext
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS CorrectOrder1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun f1(): Int {
|
||||
sb.appendLine("f1")
|
||||
return 117
|
||||
}
|
||||
|
||||
fun f2(): Int {
|
||||
sb.appendLine("f2")
|
||||
return 1
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = f1() + s1() + f2()
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
f1
|
||||
s1
|
||||
f2
|
||||
160
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS Degenerate1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1() {
|
||||
sb.appendLine("s1")
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
builder {
|
||||
s1()
|
||||
}
|
||||
|
||||
assertEquals("""
|
||||
s1
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS Degenerate2Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Unit = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(Unit)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun s2() {
|
||||
sb.appendLine("s2")
|
||||
s1()
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
builder {
|
||||
s2()
|
||||
}
|
||||
|
||||
assertEquals("""
|
||||
s2
|
||||
s1
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS FunctionReference_eqeq_nameKt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// KT-52704
|
||||
// IGNORE_BACKEND: JS_IR, JS_IR_ES6, WASM
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
suspend fun foo(x: Int) = x
|
||||
|
||||
class Foo(val x: Int) {
|
||||
suspend fun bar() = x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val ref1 = ::foo
|
||||
val rec = Foo(42)
|
||||
val ref2 = rec::bar
|
||||
val ref3 = ::foo
|
||||
val ref4 = Foo(42)::bar
|
||||
val ref5 = rec::bar
|
||||
val ref6 = Foo::bar
|
||||
assertEquals("foo", ref1.name)
|
||||
assertEquals("bar", ref2.name)
|
||||
assertEquals("bar", ref6.name)
|
||||
assertFalse(ref1 == ref2, "ref1 == ref2")
|
||||
assertTrue(ref1 == ref3, "ref1 == ref3")
|
||||
assertFalse(ref2 == ref4, "ref2 == ref4")
|
||||
assertTrue(ref2 == ref5, "ref2 == ref5")
|
||||
assertFalse(ref6 == ref2, "ref6 == ref2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// KT-66098: ClassCastException
|
||||
// IGNORE_BACKEND: WASM
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
class Foo(val x: Int) {
|
||||
suspend fun bar(y: Int) = foo(y) + x
|
||||
}
|
||||
|
||||
suspend fun foo(x: Int) = x
|
||||
|
||||
fun box(): String {
|
||||
val ref = Foo(42)::bar
|
||||
assertEquals(159, (ref as Function2<Int, Continuation<Int>, Any?>)(117, EmptyContinuation))
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// KT-66093: ClassCastException
|
||||
// IGNORE_BACKEND: JS_IR, JS_IR_ES6, WASM
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
fun foo(block: (Continuation<Unit>) -> Any?) {
|
||||
block as (suspend () -> Unit)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo {}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun foo(x: suspend () -> Int) = x()
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
val ref = ::suspendHere
|
||||
|
||||
builder {
|
||||
result = foo(ref)
|
||||
}
|
||||
|
||||
assertEquals(42, result)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun foo(label: String): String {
|
||||
val x = suspendHere()
|
||||
return label + x.toString()
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
|
||||
builder {
|
||||
result = foo("zzz")
|
||||
}
|
||||
|
||||
assertEquals("zzz42", result)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun suspendForever(): Int = suspendCoroutineUninterceptedOrReturn {
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
suspend fun foo(): Nothing {
|
||||
suspendForever()
|
||||
throw Error()
|
||||
}
|
||||
|
||||
suspend fun bar() {
|
||||
foo()
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
builder {
|
||||
bar()
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
MODULE main
|
||||
CLASS ReturnsUnit1Kt.class
|
||||
PACKAGE METADATA
|
||||
PROPERTY getSb()Ljava/lang/StringBuilder;
|
||||
Property: class.metadata.property.returnType
|
||||
K1
|
||||
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
|
||||
K2
|
||||
java/lang/StringBuilder
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// JVM_ABI_K1_K2_DIFF: KT-63864
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun s1(): Unit = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
sb.appendLine("s1")
|
||||
x.resume(Unit)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
inline suspend fun inline_s2(x: Int): Unit {
|
||||
sb.appendLine(x)
|
||||
s1()
|
||||
}
|
||||
|
||||
suspend fun s3(x: Int) {
|
||||
inline_s2(x)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
s3(117)
|
||||
}
|
||||
|
||||
sb.appendLine(result)
|
||||
|
||||
assertEquals("""
|
||||
117
|
||||
s1
|
||||
0
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = suspendHere()
|
||||
}
|
||||
|
||||
assertEquals(42, result)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// KT-66095: java.lang.ClassCastException: SuspendConversionKt$box$f$1 cannot be cast to kotlin.jvm.functions.Function1
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
val f: () -> Unit = { result = 42 }
|
||||
builder(f)
|
||||
|
||||
assertEquals(42, result)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
companion object : EmptyContinuation()
|
||||
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
|
||||
}
|
||||
|
||||
class Controller {
|
||||
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(42)
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(c: suspend Controller.() -> Unit) {
|
||||
c.startCoroutine(Controller(), EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
|
||||
builder {
|
||||
result = suspendHere()
|
||||
}
|
||||
|
||||
assertEquals(42, result)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user