diff --git a/compiler/testData/codegen/bytecodeListing/jvmRecordStructure.kt b/compiler/testData/codegen/bytecodeListing/jvmRecordStructure.kt new file mode 100644 index 00000000000..af49a7918b3 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/jvmRecordStructure.kt @@ -0,0 +1,15 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW +// WITH_RUNTIME +// JDK_15 +// IGNORE_DEXING + +interface KI { + val x: String get() = "" + val y: T +} + +@JvmRecord +data class MyRec(override val x: String, override val y: R) : KI diff --git a/compiler/testData/codegen/bytecodeListing/jvmRecordStructure.txt b/compiler/testData/codegen/bytecodeListing/jvmRecordStructure.txt new file mode 100644 index 00000000000..36367bddcad --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/jvmRecordStructure.txt @@ -0,0 +1,33 @@ +@kotlin.Metadata +public final class KI$DefaultImpls { + // source: 'jvmRecordStructure.kt' + public static @org.jetbrains.annotations.NotNull method getX(@org.jetbrains.annotations.NotNull p0: KI): java.lang.String + public final inner class KI$DefaultImpls +} + +@kotlin.Metadata +public interface KI { + // source: 'jvmRecordStructure.kt' + public abstract @org.jetbrains.annotations.NotNull method getX(): java.lang.String + public abstract method getY(): java.lang.Object + public final inner class KI$DefaultImpls +} + +@kotlin.Metadata +public final class MyRec { + // source: 'jvmRecordStructure.kt' + private final @org.jetbrains.annotations.NotNull field x: java.lang.String + private final field y: java.lang.Object + public method (@org.jetbrains.annotations.NotNull p0: java.lang.String, p1: java.lang.Object): void + public final @org.jetbrains.annotations.NotNull method component1(): java.lang.String + public final method component2(): java.lang.Object + public synthetic static method copy$default(p0: MyRec, p1: java.lang.String, p2: java.lang.Object, p3: int, p4: java.lang.Object): MyRec + public final @org.jetbrains.annotations.NotNull method copy(@org.jetbrains.annotations.NotNull p0: java.lang.String, p1: java.lang.Object): MyRec + public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean + public synthetic bridge method getX(): java.lang.String + public synthetic bridge method getY(): java.lang.Object + public method hashCode(): int + public @org.jetbrains.annotations.NotNull method toString(): java.lang.String + public @org.jetbrains.annotations.NotNull method x(): java.lang.String + public method y(): java.lang.Object +} diff --git a/compiler/testData/codegen/java15/box/records/collectionSizeOverrides.kt b/compiler/testData/codegen/java15/box/records/collectionSizeOverrides.kt new file mode 100644 index 00000000000..aaf0d2b4621 --- /dev/null +++ b/compiler/testData/codegen/java15/box/records/collectionSizeOverrides.kt @@ -0,0 +1,35 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW + +@JvmRecord +data class MyRec(override val size: Int) : Collection { + override fun contains(element: String): Boolean { + TODO("Not yet implemented") + } + + override fun containsAll(elements: Collection): Boolean { + TODO("Not yet implemented") + } + + override fun isEmpty(): Boolean { + TODO("Not yet implemented") + } + + override fun iterator(): Iterator { + TODO("Not yet implemented") + } +} + +fun box(m: MyRec, c: Collection<*>): String { + val c: Collection<*> = m + if (m.size != 56) return "fail 1" + if (c.size != 56) return "fail 2" + return "OK" +} + +fun box(): String { + val m = MyRec(56) + return box(m, m) +} diff --git a/compiler/testData/codegen/java15/box/records/propertiesOverrides.kt b/compiler/testData/codegen/java15/box/records/propertiesOverrides.kt new file mode 100644 index 00000000000..637e842b415 --- /dev/null +++ b/compiler/testData/codegen/java15/box/records/propertiesOverrides.kt @@ -0,0 +1,28 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW + +// FILE: JavaClass.java +public class JavaClass { + public static String box() { + MyRec m = new MyRec("O", "K"); + KI ki = m; + return m.x() + m.y() + ki.getX() + ki.getY(); + } +} +// FILE: main.kt + +interface KI { + val x: String get() = "" + val y: T +} + +@JvmRecord +data class MyRec(override val x: String, override val y: R) : KI + +fun box(): String { + val res = JavaClass.box() + if (res != "OKOK") return "fail 1: $res" + return "OK" +} diff --git a/compiler/testData/codegen/java15/box/records/propertiesOverridesAllCompatibilityJvmDefault.kt b/compiler/testData/codegen/java15/box/records/propertiesOverridesAllCompatibilityJvmDefault.kt new file mode 100644 index 00000000000..c0ffda1447b --- /dev/null +++ b/compiler/testData/codegen/java15/box/records/propertiesOverridesAllCompatibilityJvmDefault.kt @@ -0,0 +1,29 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW +// !JVM_DEFAULT_MODE: all-compatibility + +// FILE: JavaClass.java +public class JavaClass { + public static String box() { + MyRec m = new MyRec("O", "K"); + KI ki = m; + return m.x() + m.y() + ki.getX() + ki.getY(); + } +} +// FILE: main.kt + +interface KI { + val x: String get() = "" + val y: T +} + +@JvmRecord +data class MyRec(override val x: String, override val y: R) : KI + +fun box(): String { + val res = JavaClass.box() + if (res != "OKOK") return "fail 1: $res" + return "OK" +} diff --git a/compiler/testData/codegen/java15/box/records/propertiesOverridesEnableJvmDefault.kt b/compiler/testData/codegen/java15/box/records/propertiesOverridesEnableJvmDefault.kt new file mode 100644 index 00000000000..d3cd96abdd3 --- /dev/null +++ b/compiler/testData/codegen/java15/box/records/propertiesOverridesEnableJvmDefault.kt @@ -0,0 +1,29 @@ +// !API_VERSION: 1.5 +// !LANGUAGE: +JvmRecordSupport +// JVM_TARGET: 15 +// ENABLE_JVM_PREVIEW +// !JVM_DEFAULT_MODE: enable + +// FILE: JavaClass.java +public class JavaClass { + public static String box() { + MyRec m = new MyRec("O", "K"); + KI ki = m; + return m.x() + m.y() + ki.getX() + ki.getY(); + } +} +// FILE: main.kt + +interface KI { + val x: String get() = "" + val y: T +} + +@JvmRecord +data class MyRec(override val x: String, override val y: R) : KI + +fun box(): String { + val res = JavaClass.box() + if (res != "OKOK") return "fail 1: $res" + return "OK" +} diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt index 01078eeefbd..07a8228493a 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt @@ -60,6 +60,8 @@ abstract class KotlinBaseTest : KtUsefulTestCase() } protected open fun getTestJdkKind(files: List): TestJdkKind { + if (files.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.content, "JDK_15") }) return TestJdkKind.FULL_JDK_15 + for (file in files) { if (InTextDirectivesUtils.isDirectiveDefined(file.content, "FULL_JDK")) { return TestJdkKind.FULL_JDK diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index fa229ea4ab2..c421d32d645 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -104,6 +104,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.kt"); } + @TestMetadata("jvmRecordStructure.kt") + public void testJvmRecordStructure() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/jvmRecordStructure.kt"); + } + @TestMetadata("jvmStaticExternal.kt") public void testJvmStaticExternal() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/jvmStaticExternal.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/Jdk15BlackBoxCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/Jdk15BlackBoxCodegenTestGenerated.java index 0508221571b..f61ed7795cc 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/Jdk15BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/Jdk15BlackBoxCodegenTestGenerated.java @@ -45,11 +45,31 @@ public class Jdk15BlackBoxCodegenTestGenerated extends AbstractJdk15BlackBoxCode runTest("compiler/testData/codegen/java15/box/records/bytecodeShapeForJava.kt"); } + @TestMetadata("collectionSizeOverrides.kt") + public void testCollectionSizeOverrides() throws Exception { + runTest("compiler/testData/codegen/java15/box/records/collectionSizeOverrides.kt"); + } + @TestMetadata("dataJvmRecord.kt") public void testDataJvmRecord() throws Exception { runTest("compiler/testData/codegen/java15/box/records/dataJvmRecord.kt"); } + @TestMetadata("propertiesOverrides.kt") + public void testPropertiesOverrides() throws Exception { + runTest("compiler/testData/codegen/java15/box/records/propertiesOverrides.kt"); + } + + @TestMetadata("propertiesOverridesAllCompatibilityJvmDefault.kt") + public void testPropertiesOverridesAllCompatibilityJvmDefault() throws Exception { + runTest("compiler/testData/codegen/java15/box/records/propertiesOverridesAllCompatibilityJvmDefault.kt"); + } + + @TestMetadata("propertiesOverridesEnableJvmDefault.kt") + public void testPropertiesOverridesEnableJvmDefault() throws Exception { + runTest("compiler/testData/codegen/java15/box/records/propertiesOverridesEnableJvmDefault.kt"); + } + @TestMetadata("recordDifferentPropertyOverride.kt") public void testRecordDifferentPropertyOverride() throws Exception { runTest("compiler/testData/codegen/java15/box/records/recordDifferentPropertyOverride.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/Jdk15IrBlackBoxCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/Jdk15IrBlackBoxCodegenTestGenerated.java index a1ac4871c41..f43e9cb7d25 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/Jdk15IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/Jdk15IrBlackBoxCodegenTestGenerated.java @@ -45,11 +45,31 @@ public class Jdk15IrBlackBoxCodegenTestGenerated extends AbstractJdk15IrBlackBox runTest("compiler/testData/codegen/java15/box/records/bytecodeShapeForJava.kt"); } + @TestMetadata("collectionSizeOverrides.kt") + public void testCollectionSizeOverrides() throws Exception { + runTest("compiler/testData/codegen/java15/box/records/collectionSizeOverrides.kt"); + } + @TestMetadata("dataJvmRecord.kt") public void testDataJvmRecord() throws Exception { runTest("compiler/testData/codegen/java15/box/records/dataJvmRecord.kt"); } + @TestMetadata("propertiesOverrides.kt") + public void testPropertiesOverrides() throws Exception { + runTest("compiler/testData/codegen/java15/box/records/propertiesOverrides.kt"); + } + + @TestMetadata("propertiesOverridesAllCompatibilityJvmDefault.kt") + public void testPropertiesOverridesAllCompatibilityJvmDefault() throws Exception { + runTest("compiler/testData/codegen/java15/box/records/propertiesOverridesAllCompatibilityJvmDefault.kt"); + } + + @TestMetadata("propertiesOverridesEnableJvmDefault.kt") + public void testPropertiesOverridesEnableJvmDefault() throws Exception { + runTest("compiler/testData/codegen/java15/box/records/propertiesOverridesEnableJvmDefault.kt"); + } + @TestMetadata("recordDifferentPropertyOverride.kt") public void testRecordDifferentPropertyOverride() throws Exception { runTest("compiler/testData/codegen/java15/box/records/recordDifferentPropertyOverride.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index 16d73c5e213..98ed33c98c4 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -104,6 +104,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/jvmOverloadsExternal.kt"); } + @TestMetadata("jvmRecordStructure.kt") + public void testJvmRecordStructure() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/jvmRecordStructure.kt"); + } + @TestMetadata("jvmStaticExternal.kt") public void testJvmStaticExternal() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/jvmStaticExternal.kt");