From 5be9d5e7963db323c577b8369008869b3c8fa4eb Mon Sep 17 00:00:00 2001 From: Hui Qin Ng Date: Tue, 11 Jun 2024 08:05:25 -0700 Subject: [PATCH] Fix unexpected DCG superclass adding to data object Summary: Previous diff we mute the wrong violation to user. This diff we fix the superclass expectation Reviewed By: pengj Differential Revision: D58361681 fbshipit-source-id: a4eb24fd7daf3438981f3cbf801c0458eceec78c --- .../dataclassgenerate/DataClassGenerateBuilder.kt | 7 ++----- .../dataclassgenerate/misc/JavaDeclarationOriginExt.kt | 4 +++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/k1/src/main/kotlin/com/facebook/kotlin/compilerplugins/dataclassgenerate/DataClassGenerateBuilder.kt b/compiler/k1/src/main/kotlin/com/facebook/kotlin/compilerplugins/dataclassgenerate/DataClassGenerateBuilder.kt index 1f4700d..741540a 100644 --- a/compiler/k1/src/main/kotlin/com/facebook/kotlin/compilerplugins/dataclassgenerate/DataClassGenerateBuilder.kt +++ b/compiler/k1/src/main/kotlin/com/facebook/kotlin/compilerplugins/dataclassgenerate/DataClassGenerateBuilder.kt @@ -80,11 +80,8 @@ class DataClassGenerateBuilder( else { val originElement = declarationOrigin.descriptor if (originElement is IrBasedClassDescriptor) { - if (originElement.isData) { - // TODO(T191800312): Follow up data object support with Redex. - if (originElement.kind.isClass && - mode == PluginMode.STRICT && - !originElement.isAnnotatedWithDataClassGenerate()) { + if (originElement.isData && originElement.kind.isClass) { + if (mode == PluginMode.STRICT && !originElement.isAnnotatedWithDataClassGenerate()) { throw DataClassGenerateStrictModeViolationException( generateStrictModeViolationMessage(originElement.fqNameSafe)) } diff --git a/compiler/k1/src/main/kotlin/com/facebook/kotlin/compilerplugins/dataclassgenerate/misc/JavaDeclarationOriginExt.kt b/compiler/k1/src/main/kotlin/com/facebook/kotlin/compilerplugins/dataclassgenerate/misc/JavaDeclarationOriginExt.kt index bc8d731..5d2dc20 100644 --- a/compiler/k1/src/main/kotlin/com/facebook/kotlin/compilerplugins/dataclassgenerate/misc/JavaDeclarationOriginExt.kt +++ b/compiler/k1/src/main/kotlin/com/facebook/kotlin/compilerplugins/dataclassgenerate/misc/JavaDeclarationOriginExt.kt @@ -9,6 +9,7 @@ package com.facebook.kotlin.compilerplugins.dataclassgenerate.misc import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.descriptors.IrBasedClassDescriptor @@ -30,7 +31,8 @@ internal val JvmDeclarationOrigin.containingClassDescriptor: ClassDescriptor? } internal fun JvmDeclarationOrigin.isDataClass(): Boolean = - containingClassDescriptor?.isData ?: false + (containingClassDescriptor?.isData == true && + containingClassDescriptor?.kind == ClassKind.CLASS) ?: false internal fun JvmDeclarationOrigin.superClassLiteral(): String { val superName = containingClassDescriptor?.getSuperClassNotAny()?.fqNameOrNull()