Add some tests on corner cases for @JvmRecord

This commit is contained in:
Denis.Zharkov
2020-12-08 11:41:50 +03:00
parent 3aa55620d0
commit 920ed558ee
11 changed files with 221 additions and 0 deletions
@@ -0,0 +1,15 @@
// !API_VERSION: 1.5
// !LANGUAGE: +JvmRecordSupport
// JVM_TARGET: 15
// ENABLE_JVM_PREVIEW
// WITH_RUNTIME
// JDK_15
// IGNORE_DEXING
interface KI<T> {
val x: String get() = ""
val y: T
}
@JvmRecord
data class MyRec<R>(override val x: String, override val y: R) : KI<R>
@@ -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 <init>(@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
}
@@ -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<String> {
override fun contains(element: String): Boolean {
TODO("Not yet implemented")
}
override fun containsAll(elements: Collection<String>): Boolean {
TODO("Not yet implemented")
}
override fun isEmpty(): Boolean {
TODO("Not yet implemented")
}
override fun iterator(): Iterator<String> {
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)
}
@@ -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<String>("O", "K");
KI<String> ki = m;
return m.x() + m.y() + ki.getX() + ki.getY();
}
}
// FILE: main.kt
interface KI<T> {
val x: String get() = ""
val y: T
}
@JvmRecord
data class MyRec<R>(override val x: String, override val y: R) : KI<R>
fun box(): String {
val res = JavaClass.box()
if (res != "OKOK") return "fail 1: $res"
return "OK"
}
@@ -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<String>("O", "K");
KI<String> ki = m;
return m.x() + m.y() + ki.getX() + ki.getY();
}
}
// FILE: main.kt
interface KI<T> {
val x: String get() = ""
val y: T
}
@JvmRecord
data class MyRec<R>(override val x: String, override val y: R) : KI<R>
fun box(): String {
val res = JavaClass.box()
if (res != "OKOK") return "fail 1: $res"
return "OK"
}
@@ -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<String>("O", "K");
KI<String> ki = m;
return m.x() + m.y() + ki.getX() + ki.getY();
}
}
// FILE: main.kt
interface KI<T> {
val x: String get() = ""
val y: T
}
@JvmRecord
data class MyRec<R>(override val x: String, override val y: R) : KI<R>
fun box(): String {
val res = JavaClass.box()
if (res != "OKOK") return "fail 1: $res"
return "OK"
}
@@ -60,6 +60,8 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
}
protected open fun getTestJdkKind(files: List<F>): 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
@@ -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");
@@ -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");
@@ -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");
@@ -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");