From 882016c22f0849fa09b041736ce3113c114135a0 Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Mon, 27 Sep 2021 13:35:18 +0300 Subject: [PATCH] [IR] Add tests for KT-47342 --- .../FirBlackBoxCodegenTestGenerated.java | 12 ++++ .../codegen/box/ir/recursiveGeneric.kt | 72 +++++++++++++++++++ .../codegen/box/ir/recursiveGeneric2.kt | 68 ++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 12 ++++ .../IrBlackBoxCodegenTestGenerated.java | 12 ++++ .../LightAnalysisModeTestGenerated.java | 10 +++ .../IrJsCodegenBoxES6TestGenerated.java | 10 +++ .../IrJsCodegenBoxTestGenerated.java | 10 +++ .../semantics/JsCodegenBoxTestGenerated.java | 10 +++ .../IrCodegenBoxWasmTestGenerated.java | 10 +++ 10 files changed, 226 insertions(+) create mode 100644 compiler/testData/codegen/box/ir/recursiveGeneric.kt create mode 100644 compiler/testData/codegen/box/ir/recursiveGeneric2.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 373634a319e..ace3a482fb8 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -22864,6 +22864,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/ir/objectClass.kt"); } + @Test + @TestMetadata("recursiveGeneric.kt") + public void testRecursiveGeneric() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric.kt"); + } + + @Test + @TestMetadata("recursiveGeneric2.kt") + public void testRecursiveGeneric2() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric2.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/testData/codegen/box/ir/recursiveGeneric.kt b/compiler/testData/codegen/box/ir/recursiveGeneric.kt new file mode 100644 index 00000000000..f06cfa564c1 --- /dev/null +++ b/compiler/testData/codegen/box/ir/recursiveGeneric.kt @@ -0,0 +1,72 @@ +// IGNORE_BACKEND: WASM + +open class B + +open class BB + +interface I +interface II { + fun bar(): String = "OK" +} + +class CC : I + +inline fun > test0(a: Any): String = (a as? T != null).toString()[0].toString() + +class CCC : I, II, B() + +inline fun test1(a: Any): String where + T : I, + T : II, + T : B { + return (a as? T != null).toString()[1].toString() + } + +class CCCC : I, II + +inline fun test2(a: Any): String where + T : I, + T : II { + return (a as? T != null).toString()[2].toString() +} + +open class BX +class CI : I +class DB : BX() +class CIB : BX(), I + +inline fun , TC : BX> test3(a: Any): String { + val s1 = (a as? TC != null).toString()[3].toString() + val s2 = (a as? TI != null).toString()[3].toString() + return return s1 + s2 +} + +// KT-47342 + +object O : II> + +inline fun > testKt(): II = O as II + +fun foo(a: Any): String = a.toString() + +fun box(): String { + var result = "" + + result += foo(test0(Any())) + result += foo(test0(CC())) + + result += foo(test1(Any())) + result += foo(test1(CCC())) + + result += foo(test2(Any())) + result += foo(test2(CCCC())) + + result += foo(test3(Any())) + result += foo(test3(CI())) + result += foo(test3(DB())) + result += foo(test3(CIB())) + + if (result != "ftarlussseesee") return "FAIL: $result" + + return foo(testKt().bar()) +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ir/recursiveGeneric2.kt b/compiler/testData/codegen/box/ir/recursiveGeneric2.kt new file mode 100644 index 00000000000..49158cec97f --- /dev/null +++ b/compiler/testData/codegen/box/ir/recursiveGeneric2.kt @@ -0,0 +1,68 @@ +// IGNORE_BACKEND: WASM + +interface A +interface B +interface C + +class C1 : A, C>, B, C + +class CT1 : A, C> +class CK1 : B +class CL1 : C +class CTK1 : A, C>, B +class CTL1 : A, C>, C +class CKL1 : B, C +class CTKL1 : A, C>, B, C + +inline fun , K: B, L: C> test1(a: Any): String { + val s1 = (a as? T != null).toString()[1].toString() + val s2 = (a as? K != null).toString()[1].toString() + val s3 = (a as? L != null).toString()[1].toString() + return s1 + s2 + s3 +} + +class C2 : A, B, C + +class CT2 : A, C> +class CK2 : B +class CL2 : C +class CTK2 : A, C>, B +class CTL2 : A, C>, C +class CKL2 : B, C +class CTKL2 : A, C>, B, C + +inline fun , K: B, L: C> test2(a: Any): String { + val s1 = (a as? T != null).toString()[2].toString() + val s2 = (a as? K != null).toString()[2].toString() + val s3 = (a as? L != null).toString()[2].toString() + return s1 + s2 + s3 +} + +fun box(): String { + var result = "" + + result += test1, C>(Any()) + result += test1, C>(CT1()) + result += test1, C>(CK1()) + result += test1, C>(CL1()) + result += test1, C>(CTK1()) + result += test1, C>(CTL1()) + result += test1, C>(CKL1()) + result += test1, C>(CTKL1()) + + if (result != "aaaraaaraaarrrarararrrrr") return "FAIL1: $result" + result = "" + + result += test2(Any()) + result += test2(CT2()) + result += test2(CK2()) + result += test2(CL2()) + result += test2(CTK2()) + result += test2(CTL2()) + result += test2(CKL2()) + result += test2(CTKL2()) + + if (result != "lllulllullluuulululuuuuu") return "FAIL2: $result" + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index ea2249f8147..d7c9e822322 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -22732,6 +22732,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/ir/objectClass.kt"); } + @Test + @TestMetadata("recursiveGeneric.kt") + public void testRecursiveGeneric() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric.kt"); + } + + @Test + @TestMetadata("recursiveGeneric2.kt") + public void testRecursiveGeneric2() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric2.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index f9f6b233b55..38469f1e011 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -22864,6 +22864,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/ir/objectClass.kt"); } + @Test + @TestMetadata("recursiveGeneric.kt") + public void testRecursiveGeneric() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric.kt"); + } + + @Test + @TestMetadata("recursiveGeneric2.kt") + public void testRecursiveGeneric2() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric2.kt"); + } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index f7df6efcfd9..03ea31e553b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -19049,6 +19049,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/ir/objectClass.kt"); } + @TestMetadata("recursiveGeneric.kt") + public void testRecursiveGeneric() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric.kt"); + } + + @TestMetadata("recursiveGeneric2.kt") + public void testRecursiveGeneric2() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric2.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/ir/simple.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index e957e8350b4..aa8c6d7015e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -16148,6 +16148,16 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/ir/objectClass.kt"); } + @TestMetadata("recursiveGeneric.kt") + public void testRecursiveGeneric() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric.kt"); + } + + @TestMetadata("recursiveGeneric2.kt") + public void testRecursiveGeneric2() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric2.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/ir/simple.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index fc912f04864..547dcf7770a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -15554,6 +15554,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ir/objectClass.kt"); } + @TestMetadata("recursiveGeneric.kt") + public void testRecursiveGeneric() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric.kt"); + } + + @TestMetadata("recursiveGeneric2.kt") + public void testRecursiveGeneric2() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric2.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/ir/simple.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 543d5b5acff..26de84180bd 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -15584,6 +15584,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ir/objectClass.kt"); } + @TestMetadata("recursiveGeneric.kt") + public void testRecursiveGeneric() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric.kt"); + } + + @TestMetadata("recursiveGeneric2.kt") + public void testRecursiveGeneric2() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric2.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/ir/simple.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index e93969e538a..c0a5906ed9c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -10263,6 +10263,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/ir/objectClass.kt"); } + @TestMetadata("recursiveGeneric.kt") + public void testRecursiveGeneric() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric.kt"); + } + + @TestMetadata("recursiveGeneric2.kt") + public void testRecursiveGeneric2() throws Exception { + runTest("compiler/testData/codegen/box/ir/recursiveGeneric2.kt"); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("compiler/testData/codegen/box/ir/simple.kt");