Simplify and fix createReflectionTypeForCallableDescriptor

Previously its call sites needed to determine if the receiver type should be
ignored (e.g. if the reference is to static member or nested class constructor,
or if it's a bound reference), and 3 of 4 callers did it incorrectly. Simplify
this by passing the DoubleColonLHS instance everywhere.

Also rename it to createKCallableTypeForReference

 #KT-12738 Fixed
 #KT-12751 Fixed
 #KT-12799 Fixed
This commit is contained in:
Alexander Udalov
2016-06-21 19:16:06 +03:00
parent 6cc10aa226
commit 3eeccb407e
14 changed files with 144 additions and 31 deletions
@@ -33,8 +33,10 @@ import org.jetbrains.kotlin.idea.completion.suppressAutoInsertion
import org.jetbrains.kotlin.idea.core.*
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.util.*
import org.jetbrains.kotlin.resolve.callableReferences.createReflectionTypeForCallableDescriptor
import org.jetbrains.kotlin.resolve.PossiblyBareType
import org.jetbrains.kotlin.resolve.callableReferences.createKCallableTypeForReference
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
import org.jetbrains.kotlin.types.typeUtil.isNothing
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
@@ -248,8 +250,14 @@ private fun MutableCollection<LookupElement>.addLookupElementsForNullable(factor
fun CallableDescriptor.callableReferenceType(resolutionFacade: ResolutionFacade): FuzzyType? {
if (!CallType.CALLABLE_REFERENCE.descriptorKindFilter.accepts(this)) return null // not supported by callable references
return createReflectionTypeForCallableDescriptor(
this, null, resolutionFacade.getFrontendService(ReflectionTypes::class.java), false, resolutionFacade.moduleDescriptor
return createKCallableTypeForReference(
this,
(dispatchReceiverParameter?.type ?: extensionReceiverParameter?.type)?.let {
DoubleColonLHS.Type(it, PossiblyBareType.type(it))
},
resolutionFacade.getFrontendService(ReflectionTypes::class.java),
resolutionFacade.moduleDescriptor
)?.toFuzzyType(emptyList())
}