[Parcelize] Ignore all sealed classes in Parcelize FIR generator
Sealed classes are inherently abstract and should not have Parcelable functions added via the FIR declaration generator. #KT-59112 Fixed
This commit is contained in:
+3
-5
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.fir.plugin.createConeType
|
||||
import org.jetbrains.kotlin.fir.plugin.createMemberFunction
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
|
||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
@@ -104,15 +103,14 @@ class FirParcelizeDeclarationGenerator(session: FirSession) : FirDeclarationGene
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(SymbolInternals::class)
|
||||
override fun getCallableNamesForClass(classSymbol: FirClassSymbol<*>, context: MemberGenerationContext): Set<Name> {
|
||||
return when {
|
||||
classSymbol.fir.modality == Modality.ABSTRACT -> emptySet()
|
||||
classSymbol in matchedClasses && classSymbol.fir.modality != Modality.SEALED -> parcelizeMethodsNames
|
||||
classSymbol.rawStatus.modality == Modality.ABSTRACT || classSymbol.rawStatus.modality == Modality.SEALED -> emptySet()
|
||||
classSymbol in matchedClasses && classSymbol.rawStatus.modality != Modality.SEALED -> parcelizeMethodsNames
|
||||
else -> {
|
||||
val hasAnnotatedSealedSuperType = classSymbol.resolvedSuperTypeRefs.any {
|
||||
val superSymbol = it.type.fullyExpandedType(session).toRegularClassSymbol(session) ?: return@any false
|
||||
superSymbol.fir.modality == Modality.SEALED && superSymbol in matchedClasses
|
||||
superSymbol.rawStatus.modality == Modality.SEALED && superSymbol in matchedClasses
|
||||
}
|
||||
if (hasAnnotatedSealedSuperType) {
|
||||
parcelizeMethodsNames
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.os.Parcelable
|
||||
sealed class Foo : Parcelable {
|
||||
data class A(val x: Int) : Foo()
|
||||
object B : Foo()
|
||||
sealed class Inner : Foo()
|
||||
}
|
||||
|
||||
data class C(val x: String) : Foo()
|
||||
|
||||
@@ -15,6 +15,9 @@ class Final(val foo: String) : Parcelable
|
||||
@Parcelize
|
||||
sealed class Sealed(val foo: String) : Parcelable {
|
||||
class X : Sealed("")
|
||||
sealed class Inner : Sealed("") {
|
||||
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class Y<!> : Inner()
|
||||
}
|
||||
}
|
||||
|
||||
class Outer {
|
||||
|
||||
@@ -15,6 +15,9 @@ class Final(val foo: String) : Parcelable
|
||||
@Parcelize
|
||||
sealed class Sealed(val foo: String) : Parcelable {
|
||||
class X : Sealed("")
|
||||
sealed class Inner : Sealed("") {
|
||||
<!ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED!>class Y<!> : Inner()
|
||||
}
|
||||
}
|
||||
|
||||
class Outer {
|
||||
|
||||
Reference in New Issue
Block a user