From 507516e44d9695a4b616373f6607a89a0d37741c Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Tue, 11 May 2021 14:08:46 +0300 Subject: [PATCH] [JS IR] Add tests with reified generic and with KType on DCE to leave class --- .../semantics/IrBoxJsES6TestGenerated.java | 10 ++++ .../ir/semantics/IrBoxJsTestGenerated.java | 10 ++++ .../js/test/semantics/BoxJsTestGenerated.java | 10 ++++ .../box/reflection/kClassReifiedWithJsCall.kt | 41 +++++++++++++++++ .../box/reflection/kTypeWithJsCall.kt | 46 +++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 js/js.translator/testData/box/reflection/kClassReifiedWithJsCall.kt create mode 100644 js/js.translator/testData/box/reflection/kTypeWithJsCall.kt diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrBoxJsES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrBoxJsES6TestGenerated.java index aade6a34f26..6b4ee285d6d 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrBoxJsES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrBoxJsES6TestGenerated.java @@ -7116,6 +7116,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test { runTest("js/js.translator/testData/box/reflection/kClassOnReifiedTypeInLambda-advanced.kt"); } + @TestMetadata("kClassReifiedWithJsCall.kt") + public void testKClassReifiedWithJsCall() throws Exception { + runTest("js/js.translator/testData/box/reflection/kClassReifiedWithJsCall.kt"); + } + @TestMetadata("kClassSimpleName.kt") public void testKClassSimpleName() throws Exception { runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt"); @@ -7131,6 +7136,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test { runTest("js/js.translator/testData/box/reflection/kClassWithJsCall.kt"); } + @TestMetadata("kTypeWithJsCall.kt") + public void testKTypeWithJsCall() throws Exception { + runTest("js/js.translator/testData/box/reflection/kTypeWithJsCall.kt"); + } + @TestMetadata("primitiveKClassOnReifiedType.kt") public void testPrimitiveKClassOnReifiedType() throws Exception { runTest("js/js.translator/testData/box/reflection/primitiveKClassOnReifiedType.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java index 692c37080ae..721ff39fc6d 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java @@ -7116,6 +7116,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/reflection/kClassOnReifiedTypeInLambda-advanced.kt"); } + @TestMetadata("kClassReifiedWithJsCall.kt") + public void testKClassReifiedWithJsCall() throws Exception { + runTest("js/js.translator/testData/box/reflection/kClassReifiedWithJsCall.kt"); + } + @TestMetadata("kClassSimpleName.kt") public void testKClassSimpleName() throws Exception { runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt"); @@ -7131,6 +7136,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/reflection/kClassWithJsCall.kt"); } + @TestMetadata("kTypeWithJsCall.kt") + public void testKTypeWithJsCall() throws Exception { + runTest("js/js.translator/testData/box/reflection/kTypeWithJsCall.kt"); + } + @TestMetadata("primitiveKClassOnReifiedType.kt") public void testPrimitiveKClassOnReifiedType() throws Exception { runTest("js/js.translator/testData/box/reflection/primitiveKClassOnReifiedType.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 7ad9389b0c2..70e6d8f4007 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -7141,6 +7141,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/reflection/kClassOnReifiedTypeInLambda-advanced.kt"); } + @TestMetadata("kClassReifiedWithJsCall.kt") + public void testKClassReifiedWithJsCall() throws Exception { + runTest("js/js.translator/testData/box/reflection/kClassReifiedWithJsCall.kt"); + } + @TestMetadata("kClassSimpleName.kt") public void testKClassSimpleName() throws Exception { runTest("js/js.translator/testData/box/reflection/kClassSimpleName.kt"); @@ -7156,6 +7161,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/reflection/kClassWithJsCall.kt"); } + @TestMetadata("kTypeWithJsCall.kt") + public void testKTypeWithJsCall() throws Exception { + runTest("js/js.translator/testData/box/reflection/kTypeWithJsCall.kt"); + } + @TestMetadata("primitiveKClassOnReifiedType.kt") public void testPrimitiveKClassOnReifiedType() throws Exception { runTest("js/js.translator/testData/box/reflection/primitiveKClassOnReifiedType.kt"); diff --git a/js/js.translator/testData/box/reflection/kClassReifiedWithJsCall.kt b/js/js.translator/testData/box/reflection/kClassReifiedWithJsCall.kt new file mode 100644 index 00000000000..c0e6becc4de --- /dev/null +++ b/js/js.translator/testData/box/reflection/kClassReifiedWithJsCall.kt @@ -0,0 +1,41 @@ +import kotlin.reflect.KClass + +// MODULE: main +// FILE: main.kt +external abstract open class A( + o: String +) { + abstract val k: String + + fun test(): String +} + +class B( + o: String +) : A(o) { + override val k = "K" +} + +external fun test( + klazz: Any +) : B + +inline fun toJsClass() = T::class.js + +fun box(): String { + return test(toJsClass()).test() +} + +// FILE: test.js + +function test(classType) { + return new classType("O") +} + +function A(o) { + this.o = o +} + +A.prototype.test = function() { + return this.o + this.k +} \ No newline at end of file diff --git a/js/js.translator/testData/box/reflection/kTypeWithJsCall.kt b/js/js.translator/testData/box/reflection/kTypeWithJsCall.kt new file mode 100644 index 00000000000..00ed8052800 --- /dev/null +++ b/js/js.translator/testData/box/reflection/kTypeWithJsCall.kt @@ -0,0 +1,46 @@ +// KJS_WITH_FULL_RUNTIME + +import kotlin.reflect.KClass +import kotlin.reflect.KType +import kotlin.reflect.typeOf + +// MODULE: main +// FILE: main.kt +external abstract open class A( + o: String +) { + abstract val k: String + + fun test(): String +} + +class B( + o: String +) : A(o) { + override val k = "K" +} + +external fun test( + klazz: Any +): B + +fun toJsClass(kType: KType) = (kType.classifier as KClass<*>)?.js + +@ExperimentalStdlibApi +fun box(): String { + return test(toJsClass(typeOf())).test() +} + +// FILE: test.js + +function test(classType) { + return new classType ("O") +} + +function A(o) { + this.o = o +} + +A.prototype.test = function() { + return this.o + this.k +} \ No newline at end of file