Prohibit explicit j.l.Record supertype even for @JvmRecord
This commit is contained in:
+7
-4
@@ -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
|
||||
|
||||
+2
-2
@@ -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'. " +
|
||||
|
||||
+2
-2
@@ -7,6 +7,6 @@ class BasicRecord(val x: String)
|
||||
@JvmRecord
|
||||
data class BasicDataRecord(val x: String)
|
||||
|
||||
<!NON_DATA_CLASS_JVM_RECORD!>@JvmRecord<!>
|
||||
class BasicRecordWithSuperClass(val x: String) : Record()
|
||||
@JvmRecord
|
||||
class BasicRecordWithSuperClass(val x: String) : <!ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE!>Record()<!>
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@ data class <!JVM_RECORD_EXTENDS_CLASS!>A1<!>(val x: String) : Abstract(), I
|
||||
data class <!JVM_RECORD_EXTENDS_CLASS!>A2<!>(val x: String) : Any(), I
|
||||
|
||||
@JvmRecord
|
||||
data class A3(val x: String) : Record(), I
|
||||
data class A3(val x: String) : <!ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE!>Record()<!>, I
|
||||
|
||||
@JvmRecord
|
||||
data class A4(val x: String) : java.lang.Record(), I
|
||||
data class A4(val x: String) : <!ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE!>java.lang.Record()<!>, I
|
||||
|
||||
@JvmRecord
|
||||
data class A5(val x: String) : I
|
||||
|
||||
<!ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE!>data class A6(val x: String) : Record(), I<!>
|
||||
data class A6(val x: String) : <!ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE!>Record()<!>, I
|
||||
|
||||
<!ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE!>data class A7(val x: String) : java.lang.Record(), I<!>
|
||||
data class A7(val x: String) : <!ILLEGAL_JAVA_LANG_RECORD_SUPERTYPE!>java.lang.Record()<!>, I
|
||||
|
||||
Reference in New Issue
Block a user