diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt index 12c72120064..82569de3ccb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/BranchedFoldingUtils.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.intentions.branches +import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType @@ -66,7 +67,9 @@ object BranchedFoldingUtils { ): Boolean { val left = this.left ?: return false val otherLeft = other.left ?: return false - if (left.text != otherLeft.text || operationToken != other.operationToken) return false + if (left.text != otherLeft.text || operationToken != other.operationToken || + left.mainReference?.resolve() != otherLeft.mainReference?.resolve() + ) return false val rightType = other.rightType() ?: return false return rightType.constructor == rightTypeConstructor || (operationToken == KtTokens.EQ && rightType.isSubtypeOf(leftType)) } diff --git a/idea/testData/inspectionsLocal/liftOut/whenToAssignment/differentVariablesWithSame.kt b/idea/testData/inspectionsLocal/liftOut/whenToAssignment/differentVariablesWithSame.kt new file mode 100644 index 00000000000..32dcc87c92a --- /dev/null +++ b/idea/testData/inspectionsLocal/liftOut/whenToAssignment/differentVariablesWithSame.kt @@ -0,0 +1,18 @@ +// PROBLEM: none +// WITH_RUNTIME + +class A { + val list: MutableList = mutableListOf() +} + +class B { + val list: MutableList = mutableListOf() +} + +fun Any.add(s: String) { + when (this) { + is A -> list += s + is B -> list += s + else -> throw IllegalStateException() + } +} \ 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 5d841f87fca..10e5ab2dc8a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -5707,6 +5707,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/liftOut/whenToAssignment/cascadeWhen.kt"); } + @TestMetadata("differentVariablesWithSame.kt") + public void testDifferentVariablesWithSame() throws Exception { + runTest("idea/testData/inspectionsLocal/liftOut/whenToAssignment/differentVariablesWithSame.kt"); + } + @TestMetadata("innerWhenTransformed.kt") public void testInnerWhenTransformed() throws Exception { runTest("idea/testData/inspectionsLocal/liftOut/whenToAssignment/innerWhenTransformed.kt");