From 23b9889ebbaefe60ac95fb3ea6142ed8b685ecbd Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 7 Nov 2018 21:56:08 +0900 Subject: [PATCH] Redundant companion reference: Fix false negative in enum entry #KT-27861 Fixed --- .../inspections/RedundantCompanionReferenceInspection.kt | 1 - .../redundantCompanionReference/inEnumEntry3.kt | 7 +++++++ .../redundantCompanionReference/inEnumEntry3.kt.after | 7 +++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 5 +++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt create mode 100644 idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt index 58a0716cbe1..165d7302b4f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt @@ -41,7 +41,6 @@ class RedundantCompanionReferenceInspection : AbstractKotlinInspection() { val containingClass = objectDeclaration.containingClass() ?: return if (expression.containingClass() != containingClass && expression == parent.receiverExpression) return - if (parent.getStrictParentOfType()?.containingClass() == containingClass) return val containingClassDescriptor = containingClass.descriptor as? ClassDescriptor ?: return val selectorDescriptor = selectorExpression?.getCallableDescriptor() when (selectorDescriptor) { diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt b/idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt new file mode 100644 index 00000000000..b9c8f2b27fe --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt @@ -0,0 +1,7 @@ +enum class E(val value: String) { + E1(E.Companion.foo); + + companion object { + const val foo = "" + } +} diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt.after b/idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt.after new file mode 100644 index 00000000000..76420bd4bc5 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt.after @@ -0,0 +1,7 @@ +enum class E(val value: String) { + E1(E.foo); + + companion object { + const val foo = "" + } +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index ff9fe1fb22e..b52e0d0f978 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -3994,6 +3994,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry2.kt"); } + @TestMetadata("inEnumEntry3.kt") + public void testInEnumEntry3() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry3.kt"); + } + @TestMetadata("methodArgument.kt") public void testMethodArgument() throws Exception { runTest("idea/testData/inspectionsLocal/redundantCompanionReference/methodArgument.kt");