diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinRedundantOverrideInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinRedundantOverrideInspection.kt index 920afbe509b..fcd8f3312e6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinRedundantOverrideInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinRedundantOverrideInspection.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities @@ -58,8 +59,15 @@ class KotlinRedundantOverrideInspection : AbstractKotlinInspection(), CleanupLoc val superCallElement = qualifiedExpression.selectorExpression as? KtCallElement ?: return if (!isSameFunctionName(superCallElement, function)) return if (!isSameArguments(superCallElement, function)) return + val context = function.analyze() val functionDescriptor = context[BindingContext.FUNCTION, function] + val functionParams = functionDescriptor?.valueParameters.orEmpty() + val superCallFunctionParams = superCallElement.resolveToCall()?.resultingDescriptor?.valueParameters.orEmpty() + if (functionParams.size == superCallFunctionParams.size + && functionParams.zip(superCallFunctionParams).any { it.first.type != it.second.type } + ) return + if (function.hasDerivedProperty(functionDescriptor, context)) return val overriddenDescriptors = functionDescriptor?.original?.overriddenDescriptors if (overriddenDescriptors?.any { it is JavaMethodDescriptor && it.visibility == JavaDescriptorVisibilities.PACKAGE_VISIBILITY } == true) return diff --git a/idea/testData/inspectionsLocal/redundantOverride/callDifferentSuperMethod2.kt b/idea/testData/inspectionsLocal/redundantOverride/callDifferentSuperMethod2.kt new file mode 100644 index 00000000000..6101f33140f --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantOverride/callDifferentSuperMethod2.kt @@ -0,0 +1,16 @@ +// PROBLEM: none + +interface I { + fun foo(parent: String) +} + +open class A { + open fun foo(parent: Any) {} + +} + +class B : A(), I { + override fun foo(parent: String) { + super.foo(parent) + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 5607503a3f8..748f6b0d661 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -8419,6 +8419,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/redundantOverride/callDifferentSuperMethod.kt"); } + @TestMetadata("callDifferentSuperMethod2.kt") + public void testCallDifferentSuperMethod2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantOverride/callDifferentSuperMethod2.kt"); + } + @TestMetadata("classAndInterface.kt") public void testClassAndInterface() throws Exception { runTest("idea/testData/inspectionsLocal/redundantOverride/classAndInterface.kt");