diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt index 95e4a33a4c4..41342522c30 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt @@ -61,6 +61,7 @@ class RemoveRedundantQualifierNameInspection : AbstractKotlinInspection(), Clean val expressionParent = expression.parent if (expressionParent is KtDotQualifiedExpression || expressionParent is KtPackageDirective || expressionParent is KtImportDirective) return val expressionForAnalyze = expression.firstExpressionWithoutReceiver() ?: return + if (expressionForAnalyze.selectorExpression?.text == expressionParent.getNonStrictParentOfType()?.name) return val originalExpression: KtExpression = expressionForAnalyze.parent as? KtClassLiteralExpression ?: expressionForAnalyze diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable.kt new file mode 100644 index 00000000000..3dacee9b435 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable.kt @@ -0,0 +1,8 @@ +// PROBLEM: none +sealed class Foo { + object BAR : Foo() + + companion object { + val BAR: Foo = Foo.BAR + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable2.kt new file mode 100644 index 00000000000..9abdce68d2f --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable2.kt @@ -0,0 +1,9 @@ +// PROBLEM: none +// WITH_RUNTIME +sealed class Foo { + object BAR : Foo() + + companion object { + val BAR: Foo by lazy { Foo.BAR } + } +} \ 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 a2b6c8481e2..963b2d52a9d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -9521,6 +9521,16 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableOuterClass.kt"); } + @TestMetadata("notApplicableSameNameVariable.kt") + public void testNotApplicableSameNameVariable() throws Exception { + runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable.kt"); + } + + @TestMetadata("notApplicableSameNameVariable2.kt") + public void testNotApplicableSameNameVariable2() throws Exception { + runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableSameNameVariable2.kt"); + } + @TestMetadata("notApplicableThis.kt") public void testNotApplicableThis() throws Exception { runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableThis.kt");