diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/EqualsOrHashCodeInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/EqualsOrHashCodeInspection.kt index 7bab40031705..635121274035 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/EqualsOrHashCodeInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/EqualsOrHashCodeInspection.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol import org.jetbrains.kotlin.analysis.api.types.KtType import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.idea.base.facet.platform.platform import org.jetbrains.kotlin.idea.base.projectStructure.languageVersionSettings import org.jetbrains.kotlin.idea.base.psi.classIdIfNonLocal @@ -55,6 +56,7 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() { } private fun KtAnalysisSession.matchesEqualsMethodSignature(function: KtFunctionSymbol): Boolean { + if (function.modality == Modality.ABSTRACT) return false if (function.name != EQUALS) return false if (function.typeParameters.isNotEmpty()) return false val param = function.valueParameters.singleOrNull() ?: return false @@ -66,6 +68,7 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() { } private fun KtAnalysisSession.matchesHashCodeMethodSignature(function: KtFunctionSymbol): Boolean { + if (function.modality == Modality.ABSTRACT) return false if (function.name != HASH_CODE) return false if (function.typeParameters.isNotEmpty()) return false if (function.valueParameters.isNotEmpty()) return false @@ -341,12 +344,10 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() { Pair( classOrObjectMemberDeclarations.singleOrNull { val function = it.getSymbol() as? KtFunctionSymbol ?: return@singleOrNull false - if (function.name != EQUALS) return@singleOrNull false matchesEqualsMethodSignature(function) } as? KtNamedFunction, classOrObjectMemberDeclarations.singleOrNull { val function = it.getSymbol() as? KtFunctionSymbol ?: return@singleOrNull false - if (function.name != HASH_CODE) return@singleOrNull false matchesHashCodeMethodSignature(function) } as? KtNamedFunction, ) diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2LocalInspectionTestGenerated.java b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2LocalInspectionTestGenerated.java index 5bba50c7bcb8..b4994db79fb4 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2LocalInspectionTestGenerated.java +++ b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2LocalInspectionTestGenerated.java @@ -1671,6 +1671,11 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp runTest("../../../idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsInExpectClass.kt"); } + @TestMetadata("equalsInInterface.kt") + public void testEqualsInInterface() throws Exception { + runTest("../../../idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsInInterface.kt"); + } + @TestMetadata("equalsWithKotlinAnyParam.kt") public void testEqualsWithKotlinAnyParam() throws Exception { runTest("../../../idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsWithKotlinAnyParam.kt"); diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 00e4b85d2421..fd1bf55d1662 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -5238,6 +5238,11 @@ public abstract class LocalInspectionTestGenerated extends AbstractLocalInspecti runTest("testData/inspectionsLocal/equalsOrHashCode/equalsInExpectClass.kt"); } + @TestMetadata("equalsInInterface.kt") + public void testEqualsInInterface() throws Exception { + runTest("testData/inspectionsLocal/equalsOrHashCode/equalsInInterface.kt"); + } + @TestMetadata("equalsWithKotlinAnyParam.kt") public void testEqualsWithKotlinAnyParam() throws Exception { runTest("testData/inspectionsLocal/equalsOrHashCode/equalsWithKotlinAnyParam.kt"); diff --git a/plugins/kotlin/idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsInInterface.kt b/plugins/kotlin/idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsInInterface.kt new file mode 100644 index 000000000000..81e5e229d305 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsInInterface.kt @@ -0,0 +1,4 @@ +// PROBLEM: none +interface I { + override fun equals(other: Any?): Boolean +} \ No newline at end of file