Skip to content

Commit

Permalink
Fix unexpected DCG superclass adding to data object
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Hui Qin Ng authored and facebook-github-bot committed Jun 11, 2024
1 parent 42f8d03 commit 5be9d5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 5be9d5e

Please sign in to comment.