diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmRecordApplicabilityChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmRecordApplicabilityChecker.kt index ff54e6dccb4..76c30d583f9 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmRecordApplicabilityChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmRecordApplicabilityChecker.kt @@ -30,13 +30,16 @@ object JvmRecordApplicabilityChecker : DeclarationChecker { override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { if (descriptor !is ClassDescriptor || declaration !is KtClassOrObject) return - if (!descriptor.isJvmRecord()) { - if (descriptor.typeConstructor.supertypes.any { it.constructor.declarationDescriptor?.fqNameOrNull() == JAVA_LANG_RECORD_FQ_NAME }) { - context.trace.report(ErrorsJvm.ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE.on(declaration)) + for (supertypeEntry in declaration.superTypeListEntries) { + val supertype = context.trace[BindingContext.TYPE, supertypeEntry.typeReference] + if (supertype?.constructor?.declarationDescriptor?.fqNameOrNull() == JAVA_LANG_RECORD_FQ_NAME) { + context.trace.report(ErrorsJvm.ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE.on(supertypeEntry)) + return } - return } + if (!descriptor.isJvmRecord()) return + val reportOn = declaration.annotationEntries.firstOrNull { it.shortName == JVM_RECORD_ANNOTATION_FQ_NAME.shortName() } ?: declaration diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java index 2de395e1786..1ad721aace3 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java @@ -158,13 +158,13 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension { MAP.put(JVM_RECORD_WITHOUT_PRIMARY_CONSTRUCTOR_PARAMETERS, "Primary constructor with parameters is required for @JvmRecord class"); MAP.put(JVM_RECORD_NOT_VAL_PARAMETER, "Constructor parameter of @JvmRecord class should be a val"); MAP.put(JVM_RECORD_NOT_LAST_VARARG_PARAMETER, "Only the last constructor parameter of @JvmRecord may be a vararg"); - MAP.put(JVM_RECORD_EXTENDS_CLASS, "Record cannot inherit an other class but java.lang.Record" , RENDER_TYPE); + MAP.put(JVM_RECORD_EXTENDS_CLASS, "Record cannot inherit a class" , RENDER_TYPE); MAP.put(JVM_RECORD_REQUIRES_JDK15, "Using @JvmRecords requires at least JDK 15"); MAP.put(INNER_JVM_RECORD, "@JvmRecord class should not be inner"); MAP.put(FIELD_IN_JVM_RECORD, "It's not allowed to have non-constructor properties with backing filed in @JvmRecord class"); MAP.put(DELEGATION_BY_IN_JVM_RECORD, "Delegation is not allowed for @JvmRecord classes"); MAP.put(NON_DATA_CLASS_JVM_RECORD, "Only data classes are allowed to be marked as @JvmRecord"); - MAP.put(ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE, "Only @JvmRecord classes are allowed to have java.lang.Record supertype"); + MAP.put(ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE, "Classes cannot have explicit 'java.lang.Record' supertype"); String MESSAGE_FOR_CONCURRENT_HASH_MAP_CONTAINS = "Method 'contains' from ConcurrentHashMap may have unexpected semantics: it calls 'containsValue' instead of 'containsKey'. " + diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt b/compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt index 5d76ab12982..a3e0630a40a 100644 --- a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt +++ b/compiler/testData/diagnostics/testsWithJava15/jvmRecord/jvmRecordDescriptorStructure.kt @@ -7,6 +7,6 @@ class BasicRecord(val x: String) @JvmRecord data class BasicDataRecord(val x: String) -@JvmRecord -class BasicRecordWithSuperClass(val x: String) : Record() +@JvmRecord +class BasicRecordWithSuperClass(val x: String) : Record() diff --git a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.kt b/compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.kt index 6d7a4092a6d..2486625928b 100644 --- a/compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.kt +++ b/compiler/testData/diagnostics/testsWithJava15/jvmRecord/supertypesCheck.kt @@ -11,14 +11,14 @@ data class A1(val x: String) : Abstract(), I data class A2(val x: String) : Any(), I @JvmRecord -data class A3(val x: String) : Record(), I +data class A3(val x: String) : Record(), I @JvmRecord -data class A4(val x: String) : java.lang.Record(), I +data class A4(val x: String) : java.lang.Record(), I @JvmRecord data class A5(val x: String) : I -data class A6(val x: String) : Record(), I +data class A6(val x: String) : Record(), I -data class A7(val x: String) : java.lang.Record(), I +data class A7(val x: String) : java.lang.Record(), I