diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementsCollector.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementsCollector.kt index 1a4651d7bbd..2943cf92786 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementsCollector.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/LookupElementsCollector.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.descriptors.MemberDescriptor import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertHandler import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject +import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor import java.util.* import kotlin.math.max @@ -90,7 +91,7 @@ class LookupElementsCollector( withReceiverCast: Boolean = false, prohibitDuplicates: Boolean = false ) { - if (prohibitDuplicates && descriptor is CallableDescriptor && descriptor in processedCallables) return + if (prohibitDuplicates && descriptor is CallableDescriptor && unwrapIfImportedFromObject(descriptor) in processedCallables) return var lookupElements = lookupElementFactory.createStandardLookupElementsForDescriptor(descriptor, useReceiverTypes = true) @@ -100,7 +101,7 @@ class LookupElementsCollector( addElements(lookupElements, notImported) - if (prohibitDuplicates && descriptor is CallableDescriptor) processedCallables.add(descriptor) + if (prohibitDuplicates && descriptor is CallableDescriptor) processedCallables.add(unwrapIfImportedFromObject(descriptor)) } fun addElement(element: LookupElement, notImported: Boolean = false) { @@ -176,3 +177,6 @@ class LookupElementsCollector( resultSet.restartCompletionOnPrefixChange(prefixCondition) } } + +private fun unwrapIfImportedFromObject(descriptor: CallableDescriptor): CallableDescriptor = + if (descriptor is ImportedFromObjectCallableDescriptor<*>) descriptor.callableFromObject else descriptor diff --git a/idea/idea-completion/testData/basic/common/KT33903_1.kt b/idea/idea-completion/testData/basic/common/KT33903_1.kt new file mode 100644 index 00000000000..4c41260c1ef --- /dev/null +++ b/idea/idea-completion/testData/basic/common/KT33903_1.kt @@ -0,0 +1,13 @@ +import Obj.foo +import Obj.foo + +object Obj { + fun Any.foo() {} + + fun usage() { + Any().foo + } +} + +// EXIST: foo +// NUMBER: 1 diff --git a/idea/idea-completion/testData/basic/common/KT33903_2.kt b/idea/idea-completion/testData/basic/common/KT33903_2.kt new file mode 100644 index 00000000000..8729b3e16d6 --- /dev/null +++ b/idea/idea-completion/testData/basic/common/KT33903_2.kt @@ -0,0 +1,13 @@ +import Obj.foo +import Obj.foo + +object Obj { + fun Any.foo() {} +} + +fun usage() { + Any().foo +} + +// EXIST: foo +// NUMBER: 1 diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JSBasicCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JSBasicCompletionTestGenerated.java index 1b032af05bc..10cf29f7f6c 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JSBasicCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JSBasicCompletionTestGenerated.java @@ -441,6 +441,16 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes runTest("idea/idea-completion/testData/basic/common/KT13780_1.kt"); } + @TestMetadata("KT33903_1.kt") + public void testKT33903_1() throws Exception { + runTest("idea/idea-completion/testData/basic/common/KT33903_1.kt"); + } + + @TestMetadata("KT33903_2.kt") + public void testKT33903_2() throws Exception { + runTest("idea/idea-completion/testData/basic/common/KT33903_2.kt"); + } + @TestMetadata("LocalMultideclarationValues.kt") public void testLocalMultideclarationValues() throws Exception { runTest("idea/idea-completion/testData/basic/common/LocalMultideclarationValues.kt"); diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmBasicCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmBasicCompletionTestGenerated.java index 9b67f4f2669..b36c860fe29 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmBasicCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmBasicCompletionTestGenerated.java @@ -441,6 +441,16 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT runTest("idea/idea-completion/testData/basic/common/KT13780_1.kt"); } + @TestMetadata("KT33903_1.kt") + public void testKT33903_1() throws Exception { + runTest("idea/idea-completion/testData/basic/common/KT33903_1.kt"); + } + + @TestMetadata("KT33903_2.kt") + public void testKT33903_2() throws Exception { + runTest("idea/idea-completion/testData/basic/common/KT33903_2.kt"); + } + @TestMetadata("LocalMultideclarationValues.kt") public void testLocalMultideclarationValues() throws Exception { runTest("idea/idea-completion/testData/basic/common/LocalMultideclarationValues.kt");