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:
+2
-3
@@ -75,17 +75,16 @@ class NewResolutionOldInference(
|
|||||||
val invokeContext = outer.InvokeContext(scopeTower, name, context, tracing)
|
val invokeContext = outer.InvokeContext(scopeTower, name, context, tracing)
|
||||||
return outer.createFunctionTowerProcessor(invokeContext, explicitReceiver)
|
return outer.createFunctionTowerProcessor(invokeContext, explicitReceiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object Variable : ResolutionKind<VariableDescriptor>() {
|
object Variable : ResolutionKind<VariableDescriptor>() {
|
||||||
override fun createTowerProcessor(
|
override fun createTowerProcessor(
|
||||||
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
outer: NewResolutionOldInference, name: Name, tracing: TracingStrategy,
|
||||||
scopeTower: ScopeTower, explicitReceiver: Receiver?, context: BasicCallResolutionContext
|
scopeTower: ScopeTower, explicitReceiver: Receiver?, context: BasicCallResolutionContext
|
||||||
): ScopeTowerProcessor<MyCandidate<VariableDescriptor>> {
|
): ScopeTowerProcessor<MyCandidate<VariableDescriptor>> {
|
||||||
val simpleContext = outer.SimpleContext<VariableDescriptor>(scopeTower, name, context, tracing)
|
val simpleContext = outer.SimpleContext<VariableDescriptor>(scopeTower, name, context, tracing)
|
||||||
return createVariableProcessor(simpleContext, explicitReceiver)
|
return createVariableAndObjectProcessor(simpleContext, explicitReceiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object CallableReference : ResolutionKind<CallableDescriptor>() {
|
object CallableReference : ResolutionKind<CallableDescriptor>() {
|
||||||
|
|||||||
+2
-2
@@ -90,7 +90,7 @@ class InvokeTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candidate<Vari
|
|||||||
explicitReceiver: Receiver?
|
explicitReceiver: Receiver?
|
||||||
) : AbstractInvokeTowerProcessor<F, V>(
|
) : AbstractInvokeTowerProcessor<F, V>(
|
||||||
invokeContext,
|
invokeContext,
|
||||||
createVariableProcessor(invokeContext.contextForVariable(stripExplicitReceiver = false), explicitReceiver)
|
createVariableAndObjectProcessor(invokeContext.contextForVariable(stripExplicitReceiver = false), explicitReceiver)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// todo filter by operator
|
// todo filter by operator
|
||||||
@@ -106,7 +106,7 @@ class InvokeExtensionTowerProcessor<F : Candidate<FunctionDescriptor>, V : Candi
|
|||||||
private val explicitReceiver: ReceiverValue?
|
private val explicitReceiver: ReceiverValue?
|
||||||
) : AbstractInvokeTowerProcessor<F, V>(
|
) : AbstractInvokeTowerProcessor<F, V>(
|
||||||
invokeContext,
|
invokeContext,
|
||||||
createVariableProcessor(invokeContext.contextForVariable(stripExplicitReceiver = true), explicitReceiver = null)
|
createVariableAndObjectProcessor(invokeContext.contextForVariable(stripExplicitReceiver = true), explicitReceiver = null)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun createInvokeProcessor(variableCandidate: V): ScopeTowerProcessor<F> {
|
override fun createInvokeProcessor(variableCandidate: V): ScopeTowerProcessor<F> {
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ interface DataFlowDecorator {
|
|||||||
interface ScopeTowerLevel {
|
interface ScopeTowerLevel {
|
||||||
fun getVariables(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
|
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>>
|
fun getFunctions(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
@@ -139,5 +139,11 @@ private fun <D : CallableDescriptor, C: Candidate<D>> createSimpleProcessor(
|
|||||||
fun <C : Candidate<VariableDescriptor>> createVariableProcessor(context: TowerContext<VariableDescriptor, C>, explicitReceiver: Receiver?)
|
fun <C : Candidate<VariableDescriptor>> createVariableProcessor(context: TowerContext<VariableDescriptor, C>, explicitReceiver: Receiver?)
|
||||||
= createSimpleProcessor(context, explicitReceiver, ScopeTowerLevel::getVariables)
|
= 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?)
|
fun <C : Candidate<FunctionDescriptor>> createFunctionProcessor(context: TowerContext<FunctionDescriptor, C>, explicitReceiver: Receiver?)
|
||||||
= createSimpleProcessor(context, explicitReceiver, ScopeTowerLevel::getFunctions)
|
= createSimpleProcessor(context, explicitReceiver, ScopeTowerLevel::getFunctions)
|
||||||
|
|||||||
@@ -138,6 +138,10 @@ internal class ReceiverScopeTowerLevel(
|
|||||||
return collectMembers { getContributedVariables(name, location) }
|
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>> {
|
override fun getFunctions(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>> {
|
||||||
return collectMembers {
|
return collectMembers {
|
||||||
getContributedFunctions(name, location) + it.getInnerConstructors(name, location)
|
getContributedFunctions(name, location) + it.getInnerConstructors(name, location)
|
||||||
@@ -147,7 +151,12 @@ internal class ReceiverScopeTowerLevel(
|
|||||||
|
|
||||||
internal class QualifierScopeTowerLevel(scopeTower: ScopeTower, val qualifier: QualifierReceiver) : AbstractScopeTowerLevel(scopeTower) {
|
internal class QualifierScopeTowerLevel(scopeTower: ScopeTower, val qualifier: QualifierReceiver) : AbstractScopeTowerLevel(scopeTower) {
|
||||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?) = qualifier.staticScope
|
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)
|
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)
|
internal constructor(scopeTower: ScopeTower, lexicalScope: LexicalScope): this(scopeTower, lexicalScope as ResolutionScope)
|
||||||
|
|
||||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>>
|
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)
|
createCandidateDescriptor(it, dispatchReceiver = null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +198,6 @@ internal class SyntheticScopeBasedTowerLevel(
|
|||||||
scopeTower: ScopeTower,
|
scopeTower: ScopeTower,
|
||||||
private val syntheticScopes: SyntheticScopes
|
private val syntheticScopes: SyntheticScopes
|
||||||
): AbstractScopeTowerLevel(scopeTower) {
|
): AbstractScopeTowerLevel(scopeTower) {
|
||||||
|
|
||||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>> {
|
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<VariableDescriptor>> {
|
||||||
if (extensionReceiver == null) return emptyList()
|
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>> {
|
override fun getFunctions(name: Name, extensionReceiver: ReceiverValue?): Collection<CandidateWithBoundDispatchReceiver<FunctionDescriptor>> {
|
||||||
if (extensionReceiver == null) return emptyList()
|
if (extensionReceiver == null) return emptyList()
|
||||||
|
|
||||||
@@ -208,6 +224,9 @@ internal class HidesMembersTowerLevel(scopeTower: ScopeTower): AbstractScopeTowe
|
|||||||
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?)
|
override fun getVariables(name: Name, extensionReceiver: ReceiverValue?)
|
||||||
= getCandidates(name, extensionReceiver, LexicalScope::collectVariables)
|
= getCandidates(name, extensionReceiver, LexicalScope::collectVariables)
|
||||||
|
|
||||||
|
override fun getObjects(name: Name, extensionReceiver: ReceiverValue?)
|
||||||
|
= emptyList<CandidateWithBoundDispatchReceiver<VariableDescriptor>>()
|
||||||
|
|
||||||
override fun getFunctions(name: Name, extensionReceiver: ReceiverValue?)
|
override fun getFunctions(name: Name, extensionReceiver: ReceiverValue?)
|
||||||
= getCandidates(name, extensionReceiver, LexicalScope::collectFunctions)
|
= getCandidates(name, extensionReceiver, LexicalScope::collectFunctions)
|
||||||
|
|
||||||
@@ -247,10 +266,9 @@ private fun ResolutionScope.getContributedFunctionsAndConstructors(name: Name, l
|
|||||||
(classifier?.getTypeAliasConstructors() ?: emptyList())
|
(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))
|
val objectDescriptor = getFakeDescriptorForObject(getContributedClassifier(name, location))
|
||||||
|
return listOfNotNull(objectDescriptor)
|
||||||
return getContributedVariables(name, location) + listOfNotNull(objectDescriptor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFakeDescriptorForObject(classifier: ClassifierDescriptor?): FakeCallableDescriptorForObject? =
|
private fun getFakeDescriptorForObject(classifier: ClassifierDescriptor?): FakeCallableDescriptorForObject? =
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// !CHECK_TYPE
|
||||||
|
// KT-12322 Overload resolution ambiguity with constructor references when class has a companion object
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
companion object
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a = ::Foo
|
||||||
|
checkSubtype<() -> Foo>(a)
|
||||||
|
}
|
||||||
Vendored
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test(): kotlin.Unit
|
||||||
|
|
||||||
|
public final class Foo {
|
||||||
|
public constructor Foo()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
|
public companion object Companion {
|
||||||
|
private constructor Companion()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2291,6 +2291,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noFakeDescriptorForObject.kt")
|
||||||
|
public void testNoFakeDescriptorForObject() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/noFakeDescriptorForObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overloads.kt")
|
@TestMetadata("overloads.kt")
|
||||||
public void testOverloads() throws Exception {
|
public void testOverloads() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/overloads.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/overloads.kt");
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import bar.*
|
|||||||
/*p:foo*/A./*c:foo.A*/B./*c:foo.A.B c:foo.A.B.CO*/bar(1)
|
/*p:foo*/A./*c:foo.A*/B./*c:foo.A.B c:foo.A.B.CO*/bar(1)
|
||||||
/*p:foo*/A./*c:foo.A*/B./*c:foo.A.B*/CO./*c:foo.A.B.CO*/bar(1)
|
/*p:foo*/A./*c:foo.A*/B./*c:foo.A.B*/CO./*c:foo.A.B.CO*/bar(1)
|
||||||
/*p:foo c:foo.A(Companion)*/A
|
/*p:foo c:foo.A(Companion)*/A
|
||||||
/*p:foo p:kotlin(Int)*/A./*c:foo.A c:foo.A.Companion*/a
|
/*p:foo p:kotlin(Int)*/A./*c:foo.A.Companion c:foo.A*/a
|
||||||
/*p:foo*/A./*c:foo.A c:foo.A.Companion*/baz()
|
/*p:foo*/A./*c:foo.A c:foo.A.Companion*/baz()
|
||||||
/*p:foo c:foo.A(Companion)*/A./*c:foo.A c:foo.A.Companion*/Companion
|
/*p:foo c:foo.A(Companion)*/A./*c:foo.A.Companion c:foo.A*/Companion
|
||||||
/*p:foo*/A./*c:foo.A*/Companion./*c:foo.A.Companion*/baz()
|
/*p:foo*/A./*c:foo.A*/Companion./*c:foo.A.Companion*/baz()
|
||||||
/*p:foo c:foo.A(O)*/A./*c:foo.A c:foo.A.Companion*/O
|
/*p:foo c:foo.A(O)*/A./*c:foo.A.Companion c:foo.A*/O
|
||||||
/*p:foo p:kotlin(String)*/A./*c:foo.A*/O./*c:foo.A.O*/v = /*p:kotlin(String)*/"OK"
|
/*p:foo p:kotlin(String)*/A./*c:foo.A*/O./*c:foo.A.O*/v = /*p:kotlin(String)*/"OK"
|
||||||
/*p:foo*/A./*c:foo.A c:foo.A.Companion c:foo.A.Companion(getVala) c:foo.A.Companion(getVALA) p:foo p:bar p:java.lang p:kotlin p:kotlin.annotation p:kotlin.jvm p:kotlin.collections p:kotlin.coroutines p:kotlin.ranges p:kotlin.sequences p:kotlin.text p:kotlin.io*/vala
|
/*p:foo*/A./*c:foo.A.Companion c:foo.A c:foo.A.Companion(getVala) c:foo.A.Companion(getVALA) p:foo p:bar p:java.lang p:kotlin p:kotlin.annotation p:kotlin.jvm p:kotlin.collections p:kotlin.coroutines p:kotlin.ranges p:kotlin.sequences p:kotlin.text p:kotlin.io*/vala
|
||||||
/*p:foo*/A./*c:foo.A c:foo.A.Companion c:foo.A.Companion(getVara) c:foo.A.Companion(getVARA) p:foo p:bar p:java.lang p:kotlin p:kotlin.annotation p:kotlin.jvm p:kotlin.collections p:kotlin.coroutines p:kotlin.ranges p:kotlin.sequences p:kotlin.text p:kotlin.io*/vara()
|
/*p:foo*/A./*c:foo.A c:foo.A.Companion c:foo.A.Companion(getVara) c:foo.A.Companion(getVARA) p:foo p:bar p:java.lang p:kotlin p:kotlin.annotation p:kotlin.jvm p:kotlin.collections p:kotlin.coroutines p:kotlin.ranges p:kotlin.sequences p:kotlin.text p:kotlin.io*/vara()
|
||||||
|
|
||||||
/*p:foo(I) p:kotlin(Int)*/i./*c:foo.I*/a = /*p:kotlin(Int)*/2
|
/*p:foo(I) p:kotlin(Int)*/i./*c:foo.I*/a = /*p:kotlin(Int)*/2
|
||||||
|
|||||||
Reference in New Issue
Block a user