Do not consider fake variables for objects in :: resolution

The main change is in
NewResolutionOldInference.ResolutionKind.CallableReference, where
createVariableProcessor creates a processor which no longer lists objects

 #KT-12322 Fixed
This commit is contained in:
Alexander Udalov
2016-06-28 15:31:30 +03:00
parent f290f1be68
commit b44f060ffa
9 changed files with 74 additions and 15 deletions
@@ -90,7 +90,7 @@ class InvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<Vari
explicitReceiver: Receiver?
) : AbstractInvokeTowerProcessor<F, V>(
invokeContext,
createVariableProcessor(invokeContext.contextForVariable(stripExplicitReceiver = false), explicitReceiver)
createVariableAndObjectProcessor(invokeContext.contextForVariable(stripExplicitReceiver = false), explicitReceiver)
) {
// todo filter by operator
@@ -106,7 +106,7 @@ class InvokeExtensionTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candi
private val explicitReceiver: ReceiverValue?
) : AbstractInvokeTowerProcessor<F, V>(
invokeContext,
createVariableProcessor(invokeContext.contextForVariable(stripExplicitReceiver = true), explicitReceiver = null)
createVariableAndObjectProcessor(invokeContext.contextForVariable(stripExplicitReceiver = true), explicitReceiver = null)
) {
override fun createInvokeProcessor(variableCandidate: V): ScopeTowerProcessor<F> {
@@ -58,6 +58,8 @@ interface DataFlowDecorator {
interface ScopeTowerLevel {
fun getVariables(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
fun getObjects(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
fun getFunctions(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>>
}
@@ -139,5 +139,11 @@ private fun <D : CallableDescriptor, C: Candidate<D>> createSimpleProcessor(
fun <C : Candidate<VariableDescriptor>> createVariableProcessor(context: TowerContext<VariableDescriptor, C>, explicitReceiver: Receiver?)
= createSimpleProcessor(context, explicitReceiver, ScopeTowerLevel::getVariables)
fun <C : Candidate<VariableDescriptor>> createVariableAndObjectProcessor(context: TowerContext<VariableDescriptor, C>, explicitReceiver: Receiver?) =
CompositeScopeTowerProcessor(
createVariableProcessor(context, explicitReceiver),
createSimpleProcessor(context, explicitReceiver, ScopeTowerLevel::getObjects)
)
fun <C : Candidate<FunctionDescriptor>> createFunctionProcessor(context: TowerContext<FunctionDescriptor, C>, explicitReceiver: Receiver?)
= createSimpleProcessor(context, explicitReceiver, ScopeTowerLevel::getFunctions)
@@ -138,6 +138,10 @@ internal class ReceiverScopeTowerLevel(
return collectMembers { getContributedVariables(name, location) }
}
override fun getObjects(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>> {
return emptyList()
}
override fun getFunctions(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>> {
return collectMembers {
getContributedFunctions(name, location) + it.getInnerConstructors(name, location)
@@ -147,7 +151,12 @@ internal class ReceiverScopeTowerLevel(
internal class QualifierScopeTowerLevel(scopeTower: ScopeTower, val qualifier: QualifierReceiver) : AbstractScopeTowerLevel(scopeTower) {
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?) = qualifier.staticScope
.getContributedVariablesAndObjects(name, location).map {
.getContributedVariables(name, location).map {
createCandidateDescriptor(it, dispatchReceiver = null)
}
override fun getObjects(name: Name, extensionReceiver: ReceiverValue?) = qualifier.staticScope
.getContributedObjectVariables(name, location).map {
createCandidateDescriptor(it, dispatchReceiver = null)
}
@@ -166,7 +175,12 @@ internal open class ScopeBasedTowerLevel protected constructor(
internal constructor(scopeTower: ScopeTower, lexicalScope: LexicalScope): this(scopeTower, lexicalScope as ResolutionScope)
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
= resolutionScope.getContributedVariablesAndObjects(name, location).map {
= resolutionScope.getContributedVariables(name, location).map {
createCandidateDescriptor(it, dispatchReceiver = null)
}
override fun getObjects(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
= resolutionScope.getContributedObjectVariables(name, location).map {
createCandidateDescriptor(it, dispatchReceiver = null)
}
@@ -184,7 +198,6 @@ internal class SyntheticScopeBasedTowerLevel(
scopeTower: ScopeTower,
private val syntheticScopes: SyntheticScopes
): AbstractScopeTowerLevel(scopeTower) {
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>> {
if (extensionReceiver == null) return emptyList()
@@ -194,6 +207,9 @@ internal class SyntheticScopeBasedTowerLevel(
}
}
override fun getObjects(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
= emptyList()
override fun getFunctions(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>> {
if (extensionReceiver == null) return emptyList()
@@ -208,6 +224,9 @@ internal class HidesMembersTowerLevel(scopeTower: ScopeTower): AbstractScopeTowe
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?)
= getCandidates(name, extensionReceiver, LexicalScope::collectVariables)
override fun getObjects(name: Name, extensionReceiver: ReceiverValue?)
= emptyList<CandidateWithBoundDispatchReceiver<VariableDescriptor>>()
override fun getFunctions(name: Name, extensionReceiver: ReceiverValue?)
= getCandidates(name, extensionReceiver, LexicalScope::collectFunctions)
@@ -247,10 +266,9 @@ private fun ResolutionScope.getContributedFunctionsAndConstructors(name: Name, l
(classifier?.getTypeAliasConstructors() ?: emptyList())
}
private fun ResolutionScope.getContributedVariablesAndObjects(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
private fun ResolutionScope.getContributedObjectVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
val objectDescriptor = getFakeDescriptorForObject(getContributedClassifier(name, location))
return getContributedVariables(name, location) + listOfNotNull(objectDescriptor)
return listOfNotNull(objectDescriptor)
}
private fun getFakeDescriptorForObject(classifier: ClassifierDescriptor?): FakeCallableDescriptorForObject? =