From cbf5be5c08e175eb2af9c015cfc6e1d9fe0919ac Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 2 Oct 2015 17:03:40 +0300 Subject: [PATCH] No callable reference to generic callables --- .../src/org/jetbrains/kotlin/idea/util/CallType.kt | 8 ++++---- .../org/jetbrains/kotlin/idea/completion/smart/Utils.kt | 4 ++-- .../basic/common/callableReference/EmptyQualifier.kt | 4 ++++ .../testData/smart/callableReference/NoQualifier2.kt | 4 ++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/CallType.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/CallType.kt index 29e0389c279..cf305e0a6b1 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/CallType.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/CallType.kt @@ -48,7 +48,7 @@ public sealed class CallType(val descriptorKindFilter: object UNARY : CallType(DescriptorKindFilter.FUNCTIONS exclude NonUnaryExclude) - object CALLABLE_REFERENCE : CallType(DescriptorKindFilter.CALLABLES exclude LocalsAndSyntheticExclude/* currently not supported for locals and synthetic */) + object CALLABLE_REFERENCE : CallType(DescriptorKindFilter.CALLABLES exclude CallableReferenceExclude) object IMPORT_DIRECTIVE : CallType(DescriptorKindFilter.ALL) @@ -74,9 +74,9 @@ public sealed class CallType(val descriptorKindFilter: get() = 0 } - private object LocalsAndSyntheticExclude : DescriptorKindExclude { - override fun excludes(descriptor: DeclarationDescriptor) - = descriptor !is CallableMemberDescriptor || descriptor.kind == CallableMemberDescriptor.Kind.SYNTHESIZED + private object CallableReferenceExclude : DescriptorKindExclude { + override fun excludes(descriptor: DeclarationDescriptor) /* currently not supported for locals, synthetic and genetic */ + = descriptor !is CallableMemberDescriptor || descriptor.kind == CallableMemberDescriptor.Kind.SYNTHESIZED || descriptor.typeParameters.isNotEmpty() override val fullyExcludedDescriptorKinds: Int get() = 0 diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt index 7b3d8d9a53b..0a6aabf0dc2 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/smart/Utils.kt @@ -238,9 +238,9 @@ private fun MutableCollection.addLookupElementsForNullable(factor } fun CallableDescriptor.callableReferenceType(resolutionFacade: ResolutionFacade): FuzzyType? { + if (!CallType.CALLABLE_REFERENCE.descriptorKindFilter.accepts(this)) return null // not supported by callable references val type = getReflectionTypeForCandidateDescriptor(this, resolutionFacade.getFrontendService(ReflectionTypes::class.java)) ?: return null - //TODO: no generic - return FuzzyType(type, emptyList()/* references to generic functions not supported yet */) + return FuzzyType(type, emptyList()) } fun LookupElementFactory.createLookupElementsInSmartCompletion( diff --git a/idea/idea-completion/testData/basic/common/callableReference/EmptyQualifier.kt b/idea/idea-completion/testData/basic/common/callableReference/EmptyQualifier.kt index ae0f7e11d04..6ce20f575b7 100644 --- a/idea/idea-completion/testData/basic/common/callableReference/EmptyQualifier.kt +++ b/idea/idea-completion/testData/basic/common/callableReference/EmptyQualifier.kt @@ -9,6 +9,9 @@ var globalVar = 1 fun funWithFunctionParameter(p: () -> Unit) {} +// callable references to generic functions are not supported currently +fun genericFun(t: T): T = t + class C { fun memberFun(){} @@ -51,3 +54,4 @@ abstract class AbstractClass // ABSENT: class // ABSENT: class.java // EXIST: { itemText: "funWithFunctionParameter", tailText: "(p: () -> Unit) ()", attributes: "" } +// ABSENT: genericFun diff --git a/idea/idea-completion/testData/smart/callableReference/NoQualifier2.kt b/idea/idea-completion/testData/smart/callableReference/NoQualifier2.kt index 1e231c13e48..8bea23efd6c 100644 --- a/idea/idea-completion/testData/smart/callableReference/NoQualifier2.kt +++ b/idea/idea-completion/testData/smart/callableReference/NoQualifier2.kt @@ -7,4 +7,8 @@ fun bar() { fun f(){} fun f(i: Int){} +// currently not supported for generic funcitons +fun genericF(t: T){} + // EXIST: ::f +// ABSENT: ::genericF