Generate return when generating continuation class for expression body

Otherwise, the function will return Unit instead of correct value.
 #KT-46007 Fixed
This commit is contained in:
Ilmir Usmanov
2021-04-14 17:47:50 +02:00
committed by TeamCityServer
parent 539d3e5df2
commit 1c48fb28db
13 changed files with 399 additions and 25 deletions
@@ -9723,12 +9723,6 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt");
}
@Test
@TestMetadata("jvmDefault.kt")
public void testJvmDefault() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt");
}
@Test
@TestMetadata("overrideInInlineClass.kt")
public void testOverrideInInlineClass() throws Exception {
@@ -9877,6 +9871,56 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
public class JvmDefault {
@Test
@TestMetadata("all.kt")
public void testAll() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/all.kt");
}
@Test
public void testAllFilesPresentInJvmDefault() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007")
@TestDataPath("$PROJECT_ROOT")
public class Kt46007 {
@Test
@TestMetadata("all.kt")
public void testAll() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/all.kt");
}
@Test
public void testAllFilesPresentInKt46007() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("all-compatibility.kt")
public void testAll_compatibility() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/all-compatibility.kt");
}
@Test
@TestMetadata("disable.kt")
public void testDisable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/disable.kt");
}
@Test
@TestMetadata("enable.kt")
public void testEnable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/enable.kt");
}
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/tailrec")
@TestDataPath("$PROJECT_ROOT")
@@ -316,8 +316,12 @@ private class AddContinuationLowering(context: JvmBackendContext) : SuspendLower
function as IrAttributeContainer,
flag.capturesCrossinline
)
for (statement in newFunction.body!!.statements) {
+statement
if (newFunction.body is IrExpressionBody) {
+irReturn(newFunction.body!!.statements[0] as IrExpression)
} else {
for (statement in newFunction.body!!.statements) {
+statement
}
}
}
return result
@@ -0,0 +1,30 @@
// WITH_RUNTIME
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// IGNORE_BACKEND: JVM
// JVM_TARGET: 1.8
import kotlin.coroutines.*
class A : BlockingDoubleChain
interface BlockingDoubleChain : BlockingBufferChain
interface BlockingBufferChain {
suspend fun nextBuffer(): String = "OK"
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL"
builder {
res = A().nextBuffer()
}
return res
}
@@ -0,0 +1,28 @@
// WITH_RUNTIME
// !JVM_DEFAULT_MODE: all
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
import kotlin.coroutines.*
class A : BlockingDoubleChain
interface BlockingDoubleChain : BlockingBufferChain
interface BlockingBufferChain {
suspend fun nextBuffer(): String = "OK"
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL"
builder {
res = A().nextBuffer()
}
return res
}
@@ -0,0 +1,28 @@
// WITH_RUNTIME
// !JVM_DEFAULT_MODE: disable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
import kotlin.coroutines.*
class A : BlockingDoubleChain
interface BlockingDoubleChain : BlockingBufferChain
interface BlockingBufferChain {
suspend fun nextBuffer(): String = "OK"
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL"
builder {
res = A().nextBuffer()
}
return res
}
@@ -0,0 +1,28 @@
// WITH_RUNTIME
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
import kotlin.coroutines.*
class A : BlockingDoubleChain
interface BlockingDoubleChain : BlockingBufferChain
interface BlockingBufferChain {
suspend fun nextBuffer(): String = "OK"
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL"
builder {
res = A().nextBuffer()
}
return res
}
@@ -9723,12 +9723,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt");
}
@Test
@TestMetadata("jvmDefault.kt")
public void testJvmDefault() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt");
}
@Test
@TestMetadata("overrideInInlineClass.kt")
public void testOverrideInInlineClass() throws Exception {
@@ -9877,6 +9871,56 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
public class JvmDefault {
@Test
@TestMetadata("all.kt")
public void testAll() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/all.kt");
}
@Test
public void testAllFilesPresentInJvmDefault() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007")
@TestDataPath("$PROJECT_ROOT")
public class Kt46007 {
@Test
@TestMetadata("all.kt")
public void testAll() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/all.kt");
}
@Test
public void testAllFilesPresentInKt46007() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("all-compatibility.kt")
public void testAll_compatibility() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/all-compatibility.kt");
}
@Test
@TestMetadata("disable.kt")
public void testDisable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/disable.kt");
}
@Test
@TestMetadata("enable.kt")
public void testEnable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/enable.kt");
}
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/tailrec")
@TestDataPath("$PROJECT_ROOT")
@@ -9723,12 +9723,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt");
}
@Test
@TestMetadata("jvmDefault.kt")
public void testJvmDefault() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt");
}
@Test
@TestMetadata("overrideInInlineClass.kt")
public void testOverrideInInlineClass() throws Exception {
@@ -9877,6 +9871,56 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
public class JvmDefault {
@Test
@TestMetadata("all.kt")
public void testAll() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/all.kt");
}
@Test
public void testAllFilesPresentInJvmDefault() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007")
@TestDataPath("$PROJECT_ROOT")
public class Kt46007 {
@Test
@TestMetadata("all.kt")
public void testAll() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/all.kt");
}
@Test
public void testAllFilesPresentInKt46007() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("all-compatibility.kt")
public void testAll_compatibility() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/all-compatibility.kt");
}
@Test
@TestMetadata("disable.kt")
public void testDisable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/disable.kt");
}
@Test
@TestMetadata("enable.kt")
public void testEnable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/enable.kt");
}
}
}
@Nested
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/tailrec")
@TestDataPath("$PROJECT_ROOT")
@@ -7645,11 +7645,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt");
}
@TestMetadata("jvmDefault.kt")
public void testJvmDefault() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt");
}
@TestMetadata("overrideInInlineClass.kt")
public void testOverrideInInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/overrideInInlineClass.kt");
@@ -7792,6 +7787,57 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmDefault extends AbstractLightAnalysisModeTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@TestMetadata("all.kt")
public void testAll() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/all.kt");
}
public void testAllFilesPresentInJvmDefault() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Kt46007 extends AbstractLightAnalysisModeTest {
@TestMetadata("all-compatibility.kt")
public void ignoreAll_compatibility() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/all-compatibility.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@TestMetadata("all.kt")
public void testAll() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/all.kt");
}
public void testAllFilesPresentInKt46007() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("disable.kt")
public void testDisable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/disable.kt");
}
@TestMetadata("enable.kt")
public void testEnable() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007/enable.kt");
}
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/tailrec")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -6951,6 +6951,32 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmDefault extends AbstractIrJsCodegenBoxES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInJvmDefault() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Kt46007 extends AbstractIrJsCodegenBoxES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInKt46007() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/tailrec")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -6372,6 +6372,32 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmDefault extends AbstractIrJsCodegenBoxTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
}
public void testAllFilesPresentInJvmDefault() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Kt46007 extends AbstractIrJsCodegenBoxTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
}
public void testAllFilesPresentInKt46007() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/tailrec")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -6372,6 +6372,32 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmDefault extends AbstractJsCodegenBoxTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
}
public void testAllFilesPresentInJvmDefault() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Kt46007 extends AbstractJsCodegenBoxTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
}
public void testAllFilesPresentInKt46007() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault/kt46007"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/featureIntersection/tailrec")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)