From 1c4567c999a3fcfdc4b0b873bc0c2068b2996e48 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 23 Sep 2020 16:16:01 +0300 Subject: [PATCH] Add tests for KT-40152 --- .../ir/FirBlackBoxCodegenTestGenerated.java | 5 +++ .../box/collections/removeNullFromList.kt | 34 +++++++++++++++++++ .../collectionStubs/collectionByDelegation.kt | 4 +++ .../collectionByDelegation.txt | 29 ++++++++++++++++ .../collectionByDelegation_ir.txt | 29 ++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++ .../codegen/BytecodeListingTestGenerated.java | 5 +++ .../LightAnalysisModeTestGenerated.java | 5 +++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++ .../ir/IrBytecodeListingTestGenerated.java | 5 +++ 10 files changed, 126 insertions(+) create mode 100644 compiler/testData/codegen/box/collections/removeNullFromList.kt create mode 100644 compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.kt create mode 100644 compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.txt create mode 100644 compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation_ir.txt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 57df44f5be3..d41e2d650eb 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -5043,6 +5043,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/collections/removeClashWithGenerics.kt"); } + @TestMetadata("removeNullFromList.kt") + public void testRemoveNullFromList() throws Exception { + runTest("compiler/testData/codegen/box/collections/removeNullFromList.kt"); + } + @TestMetadata("removeOverriddenInJava.kt") public void testRemoveOverriddenInJava() throws Exception { runTest("compiler/testData/codegen/box/collections/removeOverriddenInJava.kt"); diff --git a/compiler/testData/codegen/box/collections/removeNullFromList.kt b/compiler/testData/codegen/box/collections/removeNullFromList.kt new file mode 100644 index 00000000000..a97ab4f6f89 --- /dev/null +++ b/compiler/testData/codegen/box/collections/removeNullFromList.kt @@ -0,0 +1,34 @@ +// TARGET_BACKEND: JVM +// FILE: removeNullFromList.kt + +class MyList : List { + override val size: Int get() = 0 + override fun contains(element: String): Boolean = false + override fun containsAll(elements: Collection): Boolean = false + override fun get(index: Int): String = TODO() + override fun indexOf(element: String): Int = -1 + override fun isEmpty(): Boolean = true + override fun iterator(): Iterator = TODO() + override fun lastIndexOf(element: String): Int = -1 + override fun listIterator(): ListIterator = TODO() + override fun listIterator(index: Int): ListIterator = TODO() + override fun subList(fromIndex: Int, toIndex: Int): List = this +} + +fun box(): String { + try { + J.test(MyList()) + } catch (e: UnsupportedOperationException) { + return "OK" + } + return "J.test(MyList()) should have thrown UnsupportedOperationException" +} + +// FILE: J.java +import java.util.List; + +public class J { + public static void test(List list) { + list.remove(null); + } +} diff --git a/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.kt b/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.kt new file mode 100644 index 00000000000..78ef49ecd66 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.kt @@ -0,0 +1,4 @@ +class SimplePlatform + +open class TargetPlatform(val componentPlatforms: Set) : + Collection by componentPlatforms \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.txt b/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.txt new file mode 100644 index 00000000000..aa7eca5ca01 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.txt @@ -0,0 +1,29 @@ +@kotlin.Metadata +public final class SimplePlatform { + // source: 'collectionByDelegation.kt' + public method (): void +} + +@kotlin.Metadata +public class TargetPlatform { + // source: 'collectionByDelegation.kt' + private final @org.jetbrains.annotations.NotNull field componentPlatforms: java.util.Set + public method (@org.jetbrains.annotations.NotNull p0: java.util.Set): void + public method add(p0: SimplePlatform): boolean + public synthetic method add(p0: java.lang.Object): boolean + public method addAll(p0: java.util.Collection): boolean + public method clear(): void + public method contains(@org.jetbrains.annotations.NotNull p0: SimplePlatform): boolean + public bridge final method contains(p0: java.lang.Object): boolean + public method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public final @org.jetbrains.annotations.NotNull method getComponentPlatforms(): java.util.Set + public method getSize(): int + public method isEmpty(): boolean + public @org.jetbrains.annotations.NotNull method iterator(): java.util.Iterator + public method remove(p0: java.lang.Object): boolean + public method removeAll(p0: java.util.Collection): boolean + public method retainAll(p0: java.util.Collection): boolean + public bridge final method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] +} diff --git a/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation_ir.txt b/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation_ir.txt new file mode 100644 index 00000000000..fa1f8b102a3 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation_ir.txt @@ -0,0 +1,29 @@ +@kotlin.Metadata +public final class SimplePlatform { + // source: 'collectionByDelegation.kt' + public method (): void +} + +@kotlin.Metadata +public class TargetPlatform { + // source: 'collectionByDelegation.kt' + private final @org.jetbrains.annotations.NotNull field componentPlatforms: java.util.Set + public method (@org.jetbrains.annotations.NotNull p0: java.util.Set): void + public method add(p0: SimplePlatform): boolean + public synthetic bridge method add(p0: java.lang.Object): boolean + public method addAll(p0: java.util.Collection): boolean + public method clear(): void + public method contains(@org.jetbrains.annotations.NotNull p0: SimplePlatform): boolean + public bridge final method contains(p0: java.lang.Object): boolean + public method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public final @org.jetbrains.annotations.NotNull method getComponentPlatforms(): java.util.Set + public method getSize(): int + public method isEmpty(): boolean + public @org.jetbrains.annotations.NotNull method iterator(): java.util.Iterator + public method remove(p0: java.lang.Object): boolean + public method removeAll(p0: java.util.Collection): boolean + public method retainAll(p0: java.util.Collection): boolean + public bridge final method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 409caa8b8ee..507a1906ba5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -5073,6 +5073,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/collections/removeClashWithGenerics.kt"); } + @TestMetadata("removeNullFromList.kt") + public void testRemoveNullFromList() throws Exception { + runTest("compiler/testData/codegen/box/collections/removeNullFromList.kt"); + } + @TestMetadata("removeOverriddenInJava.kt") public void testRemoveOverriddenInJava() throws Exception { runTest("compiler/testData/codegen/box/collections/removeOverriddenInJava.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index 0b4fa3d2af0..2702452a706 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -229,6 +229,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/collectionStubs"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @TestMetadata("collectionByDelegation.kt") + public void testCollectionByDelegation() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.kt"); + } + @TestMetadata("collectionsWithFullJdk.kt") public void testCollectionsWithFullJdk() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/collectionStubs/collectionsWithFullJdk.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index f979302cbcc..4b297c5d56a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -5073,6 +5073,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/collections/removeClashWithGenerics.kt"); } + @TestMetadata("removeNullFromList.kt") + public void testRemoveNullFromList() throws Exception { + runTest("compiler/testData/codegen/box/collections/removeNullFromList.kt"); + } + @TestMetadata("removeOverriddenInJava.kt") public void testRemoveOverriddenInJava() throws Exception { runTest("compiler/testData/codegen/box/collections/removeOverriddenInJava.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 9d999c4a6eb..f9c332fbd62 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -5043,6 +5043,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/collections/removeClashWithGenerics.kt"); } + @TestMetadata("removeNullFromList.kt") + public void testRemoveNullFromList() throws Exception { + runTest("compiler/testData/codegen/box/collections/removeNullFromList.kt"); + } + @TestMetadata("removeOverriddenInJava.kt") public void testRemoveOverriddenInJava() throws Exception { runTest("compiler/testData/codegen/box/collections/removeOverriddenInJava.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index 03262345b1a..ac6d54edf85 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -229,6 +229,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/collectionStubs"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("collectionByDelegation.kt") + public void testCollectionByDelegation() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/collectionStubs/collectionByDelegation.kt"); + } + @TestMetadata("collectionsWithFullJdk.kt") public void testCollectionsWithFullJdk() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/collectionStubs/collectionsWithFullJdk.kt");