From 8cdef13537faaba9243b7d181df7f0a8e587573a Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Wed, 5 Feb 2020 16:00:00 -0800 Subject: [PATCH] [JVM IR] Add tests to verify correct parameter reflection metadata for suspend functions. --- .../box/parametersMetadata/suspendFunction.kt | 25 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 14 +++++++++++ .../LightAnalysisModeTestGenerated.java | 24 ++++++++++++++---- .../ir/FirBlackBoxCodegenTestGenerated.java | 9 +++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 9 +++++++ .../IrJsCodegenBoxTestGenerated.java | 4 +++ .../semantics/JsCodegenBoxTestGenerated.java | 4 +++ 7 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt diff --git a/compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt b/compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt new file mode 100644 index 00000000000..0f3c48f1cb5 --- /dev/null +++ b/compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt @@ -0,0 +1,25 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// SKIP_JDK6 +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FULL_JDK +// KOTLIN_CONFIGURATION_FLAGS: +JVM.PARAMETERS_METADATA +// COMMON_COROUTINES_TEST +import COROUTINES_PACKAGE.* +import COROUTINES_PACKAGE.intrinsics.* + +class A() { + suspend fun test(OK: String) { + + } +} + +fun box(): String { + val clazz = A::class.java + val method = clazz.getDeclaredMethod("test", String::class.java, Continuation::class.java) + val parameters = method.getParameters() + + if (parameters[0].modifiers != 0) return "wrong modifier on value parameter: ${parameters[0].modifiers}" + if (parameters[1].modifiers != 0) return "wrong modifier on Continuation parameter: ${parameters[1].modifiers}" + return parameters[0].name +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 991c50117fd..2be4cbcf178 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -18560,6 +18560,10 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.JVM, testDataFilePath); + } + public void testAllFilesPresentInParametersMetadata() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/parametersMetadata"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } @@ -18608,6 +18612,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testSuperParams() throws Exception { runTest("compiler/testData/codegen/box/parametersMetadata/superParams.kt"); } + + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt", "kotlin.coroutines"); + } } @TestMetadata("compiler/testData/codegen/box/platformTypes") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index cb9171c27c9..93ed5ae771b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -14693,6 +14693,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class NotNullAssertions extends AbstractLightAnalysisModeTest { + @TestMetadata("paramAssertionMessage.kt") + public void ignoreParamAssertionMessage() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt"); + } + private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -14776,11 +14781,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt"); } - @TestMetadata("paramAssertionMessage.kt") - public void testParamAssertionMessage() throws Exception { - runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt"); - } - @TestMetadata("staticCallErrorMessage.kt") public void testStaticCallErrorMessage() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt"); @@ -18560,6 +18560,10 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.JVM, testDataFilePath); + } + public void testAllFilesPresentInParametersMetadata() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/parametersMetadata"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } @@ -18608,6 +18612,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testSuperParams() throws Exception { runTest("compiler/testData/codegen/box/parametersMetadata/superParams.kt"); } + + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt", "kotlin.coroutines"); + } } @TestMetadata("compiler/testData/codegen/box/platformTypes") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 0c7dab69208..2f75f97bc51 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -17069,6 +17069,10 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); } + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTestWithCustomIgnoreDirective(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); + } + public void testAllFilesPresentInParametersMetadata() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/parametersMetadata"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } @@ -17117,6 +17121,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testSuperParams() throws Exception { runTest("compiler/testData/codegen/box/parametersMetadata/superParams.kt"); } + + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt", "kotlin.coroutines"); + } } @TestMetadata("compiler/testData/codegen/box/platformTypes") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 820f56e0c25..dcab3eb9f13 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -17069,6 +17069,10 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); } + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.JVM_IR, testDataFilePath); + } + public void testAllFilesPresentInParametersMetadata() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/parametersMetadata"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } @@ -17117,6 +17121,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testSuperParams() throws Exception { runTest("compiler/testData/codegen/box/parametersMetadata/superParams.kt"); } + + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/parametersMetadata/suspendFunction.kt", "kotlin.coroutines"); + } } @TestMetadata("compiler/testData/codegen/box/platformTypes") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index aab141321f3..81c6064486c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -14295,6 +14295,10 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); } + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest0(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.JS_IR, testDataFilePath); + } + public void testAllFilesPresentInParametersMetadata() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/parametersMetadata"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index c3442b872bf..e49e3c3660c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -14400,6 +14400,10 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); } + private void runTestWithPackageReplacement(String testDataFilePath, String packageName) throws Exception { + KotlinTestUtils.runTest0(filePath -> doTestWithCoroutinesPackageReplacement(filePath, packageName), TargetBackend.JS, testDataFilePath); + } + public void testAllFilesPresentInParametersMetadata() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/parametersMetadata"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); }