K2: serialize data class equals / hashCode / toString functions
#KT-57510 Fixed
This commit is contained in:
committed by
Space Team
parent
0a38b29491
commit
563781a246
+14
-5
@@ -296,13 +296,22 @@ class FirElementSerializer private constructor(
|
||||
|
||||
processScope(memberScope) l@{
|
||||
val declaration = it.fir as T
|
||||
if (declaration.isSubstitutionOrIntersectionOverride) return@l
|
||||
|
||||
// non-intersection or substitution fake override
|
||||
if (!(declaration.isStatic || declaration is FirConstructor)) {
|
||||
if (declaration.dispatchReceiverClassLookupTagOrNull() != this@collectDeclarations.symbol.toLookupTag()) {
|
||||
val dispatchReceiverLookupTag = declaration.dispatchReceiverClassLookupTagOrNull()
|
||||
// Special case for data/value class equals/hashCode/toString, see KT-57510
|
||||
val isOverrideOfAnyFunctionInDataOrValueClass = this@collectDeclarations is FirRegularClass &&
|
||||
(this@collectDeclarations.isData || this@collectDeclarations.isInline) &&
|
||||
dispatchReceiverLookupTag?.classId == StandardClassIds.Any && !declaration.isFinal
|
||||
if (declaration.isSubstitutionOrIntersectionOverride) {
|
||||
if (!isOverrideOfAnyFunctionInDataOrValueClass) {
|
||||
return@l
|
||||
}
|
||||
} else if (!(declaration.isStatic || declaration is FirConstructor)) {
|
||||
// non-intersection or substitution fake override
|
||||
if (dispatchReceiverLookupTag != this@collectDeclarations.symbol.toLookupTag()) {
|
||||
if (!isOverrideOfAnyFunctionInDataOrValueClass) {
|
||||
return@l
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add(declaration)
|
||||
|
||||
@@ -42,6 +42,14 @@ inline fun <reified T> test(vararg names: String) {
|
||||
assertEquals(names.toSet(), T::class.declaredMembers.map { it.name }.toSet())
|
||||
}
|
||||
|
||||
data class D(val x: Int)
|
||||
|
||||
open class O<T>(val y: T)
|
||||
data class DO(val z: Int) : O<Int>(2 * z)
|
||||
|
||||
@JvmInline
|
||||
value class V(val b: Boolean)
|
||||
|
||||
fun box(): String {
|
||||
class Local : L() {
|
||||
fun publicLocalFun() {}
|
||||
@@ -55,6 +63,9 @@ fun box(): String {
|
||||
test<K>("publicKFun", "privateKFun", "publicKProp", "privateKProp")
|
||||
test<L>("publicLFun", "privateLFun", "publicLProp", "privateLProp")
|
||||
test<Local>("publicLocalFun", "privateLocalFun", "publicLocalProp", "privateLocalProp")
|
||||
test<D>("x", "component1", "copy", "equals", "hashCode", "toString")
|
||||
test<DO>("z", "component1", "copy", "equals", "hashCode", "toString")
|
||||
test<V>("b", "equals", "hashCode", "toString")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user