diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt index d3e13b5a0f8..eee2997aafa 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/ShortenReferences.kt @@ -603,6 +603,10 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT } override fun analyzeQualifiedElement(element: KtDotQualifiedExpression, bindingContext: BindingContext): AnalyzeQualifiedElementResult { + val parent = element.parent + // TODO: Delete this code when KT-13934 is fixed + if (parent is KtCallableReferenceExpression && parent.receiverExpression == element) return AnalyzeQualifiedElementResult.Skip + val receiver = element.receiverExpression if (PsiTreeUtil.getParentOfType( @@ -616,7 +620,7 @@ class ShortenReferences(val options: (KtElement) -> Options = { Options.DEFAULT if (receiverTarget.companionObjectDescriptor != selectorTarget) return AnalyzeQualifiedElementResult.Skip - val selectorsSelector = (element.parent as? KtDotQualifiedExpression)?.selectorExpression + val selectorsSelector = (parent as? KtDotQualifiedExpression)?.selectorExpression ?: return AnalyzeQualifiedElementResult.ShortenNow val selectorsSelectorTarget = selectorsSelector.singleTarget(bindingContext) ?: return AnalyzeQualifiedElementResult.Skip diff --git a/idea/testData/shortenRefs/callableRefsOnCompanion.kt b/idea/testData/shortenRefs/callableRefsOnCompanion.kt new file mode 100644 index 00000000000..8bb3ca0a102 --- /dev/null +++ b/idea/testData/shortenRefs/callableRefsOnCompanion.kt @@ -0,0 +1,20 @@ +package test + +class A { + companion object { + fun foo() { + + } + } +} + +fun A.Companion.bar() { + +} + +fun test() { + A.Companion::foo + A.Companion::bar + (A.Companion)::foo + (A.Companion)::bar +} \ No newline at end of file diff --git a/idea/testData/shortenRefs/callableRefsOnCompanion.kt.after b/idea/testData/shortenRefs/callableRefsOnCompanion.kt.after new file mode 100644 index 00000000000..376222683a7 --- /dev/null +++ b/idea/testData/shortenRefs/callableRefsOnCompanion.kt.after @@ -0,0 +1,20 @@ +package test + +class A { + companion object { + fun foo() { + + } + } +} + +fun A.Companion.bar() { + +} + +fun test() { + A.Companion::foo + A.Companion::bar + (A)::foo + (A)::bar +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/shortenRefs/ShortenRefsTestGenerated.java b/idea/tests/org/jetbrains/kotlin/shortenRefs/ShortenRefsTestGenerated.java index 8edbc7ad4b6..312e7e19555 100644 --- a/idea/tests/org/jetbrains/kotlin/shortenRefs/ShortenRefsTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/shortenRefs/ShortenRefsTestGenerated.java @@ -42,6 +42,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest { doTest(fileName); } + @TestMetadata("callableRefsOnCompanion.kt") + public void testCallableRefsOnCompanion() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/callableRefsOnCompanion.kt"); + doTest(fileName); + } + @TestMetadata("ClassNameConflict.kt") public void testClassNameConflict() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/shortenRefs/ClassNameConflict.kt");