Inspections: Forbid equals/hashCode inspection on object with explicit supertypes
#KT-9778 Fixed
This commit is contained in:
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtVisitorVoid
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
import org.jetbrains.kotlin.types.typeUtil.supertypes
|
||||
|
||||
object DeleteEqualsAndHashCodeFix : LocalQuickFix {
|
||||
override fun getName() = "Delete equals()/hashCode()"
|
||||
@@ -76,6 +77,7 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() {
|
||||
|
||||
when (classDescriptor.kind) {
|
||||
ClassKind.OBJECT -> {
|
||||
if (classOrObject.getDelegationSpecifiers().isNotEmpty()) return
|
||||
holder.registerProblem(nameIdentifier, "equals()/hashCode() in object declaration", DeleteEqualsAndHashCodeFix)
|
||||
}
|
||||
ClassKind.CLASS -> {
|
||||
|
||||
@@ -36,4 +36,14 @@ interface I {
|
||||
enum E {
|
||||
override fun equals(other: Any?) = true
|
||||
override fun hashCode() = 0
|
||||
}
|
||||
|
||||
abstract class T
|
||||
|
||||
object O4 : A() {
|
||||
override fun equals(other: Any?) = true
|
||||
}
|
||||
|
||||
object O5 : A() {
|
||||
override fun hashCode() = 0
|
||||
}
|
||||
Reference in New Issue
Block a user