From b6a5d30469536498cafb9aed6264bc082a401915 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 19 Nov 2015 20:31:57 +0300 Subject: [PATCH] Inspections: Forbid equals/hashCode inspection on object with explicit supertypes #KT-9778 Fixed --- .../idea/inspections/EqualsOrHashCodeInspection.kt | 2 ++ idea/testData/inspections/equalsAndHashCode/test.kt | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/EqualsOrHashCodeInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/EqualsOrHashCodeInspection.kt index a08db2b84a9..30d981b0672 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/EqualsOrHashCodeInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/EqualsOrHashCodeInspection.kt @@ -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 -> { diff --git a/idea/testData/inspections/equalsAndHashCode/test.kt b/idea/testData/inspections/equalsAndHashCode/test.kt index 2bd043e6030..2d40a3cd466 100644 --- a/idea/testData/inspections/equalsAndHashCode/test.kt +++ b/idea/testData/inspections/equalsAndHashCode/test.kt @@ -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 } \ No newline at end of file