[NI] Improve diagnostic about unresolved receiver for many candidates
This commit is contained in:
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.tower
|
||||
@@ -201,19 +190,7 @@ class PSICallResolver(
|
||||
}
|
||||
|
||||
result.diagnostics.firstIsInstanceOrNull<ManyCandidatesCallDiagnostic>()?.let {
|
||||
val resolvedCalls = it.candidates.map { kotlinToResolvedCallTransformer.onlyTransform<D>(it.resolvedCall, emptyList()) }
|
||||
if (it.candidates.areAllFailed()) {
|
||||
tracingStrategy.noneApplicable(trace, resolvedCalls)
|
||||
tracingStrategy.recordAmbiguity(trace, resolvedCalls)
|
||||
} else {
|
||||
tracingStrategy.recordAmbiguity(trace, resolvedCalls)
|
||||
if (resolvedCalls.first().status == ResolutionStatus.INCOMPLETE_TYPE_INFERENCE) {
|
||||
tracingStrategy.cannotCompleteResolve(trace, resolvedCalls)
|
||||
} else {
|
||||
tracingStrategy.ambiguity(trace, resolvedCalls)
|
||||
}
|
||||
}
|
||||
return ManyCandidates(resolvedCalls)
|
||||
return transformManyCandidatesAndRecordTrace(it, tracingStrategy, trace)
|
||||
}
|
||||
|
||||
val isInapplicableReceiver =
|
||||
@@ -235,6 +212,31 @@ class PSICallResolver(
|
||||
return SingleOverloadResolutionResult(resolvedCall)
|
||||
}
|
||||
|
||||
private fun <D : CallableDescriptor> transformManyCandidatesAndRecordTrace(
|
||||
diagnostic: ManyCandidatesCallDiagnostic,
|
||||
tracingStrategy: TracingStrategy,
|
||||
trace: BindingTrace
|
||||
): ManyCandidates<D> {
|
||||
val resolvedCalls = diagnostic.candidates.map { kotlinToResolvedCallTransformer.onlyTransform<D>(it.resolvedCall, emptyList()) }
|
||||
|
||||
if (diagnostic.candidates.areAllFailed()) {
|
||||
if (diagnostic.candidates.areAllFailedWithInapplicableWrongReceiver()) {
|
||||
tracingStrategy.unresolvedReferenceWrongReceiver(trace, resolvedCalls)
|
||||
} else {
|
||||
tracingStrategy.noneApplicable(trace, resolvedCalls)
|
||||
tracingStrategy.recordAmbiguity(trace, resolvedCalls)
|
||||
}
|
||||
} else {
|
||||
tracingStrategy.recordAmbiguity(trace, resolvedCalls)
|
||||
if (resolvedCalls.first().status == ResolutionStatus.INCOMPLETE_TYPE_INFERENCE) {
|
||||
tracingStrategy.cannotCompleteResolve(trace, resolvedCalls)
|
||||
} else {
|
||||
tracingStrategy.ambiguity(trace, resolvedCalls)
|
||||
}
|
||||
}
|
||||
return ManyCandidates(resolvedCalls)
|
||||
}
|
||||
|
||||
private fun ResolvedCall<*>.recordEffects(trace: BindingTrace) {
|
||||
val moduleDescriptor = DescriptorUtils.getContainingModule(this.resultingDescriptor?.containingDeclaration ?: return)
|
||||
recordLambdasInvocations(trace, moduleDescriptor)
|
||||
@@ -259,6 +261,11 @@ class PSICallResolver(
|
||||
!it.resultingApplicability.isSuccess
|
||||
}
|
||||
|
||||
private fun Collection<KotlinResolutionCandidate>.areAllFailedWithInapplicableWrongReceiver() =
|
||||
all {
|
||||
it.resultingApplicability == ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
||||
}
|
||||
|
||||
private fun CallResolutionResult.areAllInapplicable(): Boolean {
|
||||
val manyCandidates = diagnostics.firstIsInstanceOrNull<ManyCandidatesCallDiagnostic>()?.candidates
|
||||
if (manyCandidates != null) {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
val <!UNUSED_VARIABLE!>a<!> = <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>-<!>false
|
||||
}
|
||||
|
||||
operator fun A.unaryMinus() {}
|
||||
operator fun B.unaryMinus() {}
|
||||
class A
|
||||
class B
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
public operator fun A.unaryMinus(): kotlin.Unit
|
||||
public operator fun B.unaryMinus(): kotlin.Unit
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
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 final class B {
|
||||
public constructor B()
|
||||
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
|
||||
}
|
||||
Vendored
+3
-3
@@ -7,8 +7,8 @@ fun Int.invoke(a: Int, b: Int) {}
|
||||
class SomeClass
|
||||
|
||||
fun test(identifier: SomeClass, fn: String.() -> Unit) {
|
||||
<!NI;NONE_APPLICABLE, OI;DEBUG_INFO_MISSING_UNRESOLVED, OI;FUNCTION_EXPECTED!>identifier<!>()
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>identifier<!>(123)
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>identifier<!>(1, 2)
|
||||
<!FUNCTION_EXPECTED, DEBUG_INFO_MISSING_UNRESOLVED!>identifier<!>()
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>identifier<!>(123)
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>identifier<!>(1, 2)
|
||||
1.<!NI;DEBUG_INFO_MISSING_UNRESOLVED!><!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE_WRONG_RECEIVER!>fn<!>()<!>
|
||||
}
|
||||
Vendored
+14
-15
@@ -1,4 +1,3 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A
|
||||
@@ -20,20 +19,20 @@ class E {
|
||||
// `bar` calls are inapplicable since both E nor D aren't proper receivers
|
||||
// But prior to this change, every lambda was analyzed repeatedly for every candidate
|
||||
// Thus, the resulting time was exponential
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!NI;NONE_APPLICABLE, OI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>bar<!> {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11365,6 +11365,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("reportUnresolvedReferenceWrongReceiverForManyCandidates.kt")
|
||||
public void testReportUnresolvedReferenceWrongReceiverForManyCandidates() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/reportUnresolvedReferenceWrongReceiverForManyCandidates.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("subtypeForInvariantWithErrorGenerics.kt")
|
||||
public void testSubtypeForInvariantWithErrorGenerics() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.kt");
|
||||
|
||||
Generated
+6
@@ -11365,6 +11365,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("reportUnresolvedReferenceWrongReceiverForManyCandidates.kt")
|
||||
public void testReportUnresolvedReferenceWrongReceiverForManyCandidates() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/reportUnresolvedReferenceWrongReceiverForManyCandidates.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("subtypeForInvariantWithErrorGenerics.kt")
|
||||
public void testSubtypeForInvariantWithErrorGenerics() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.kt");
|
||||
|
||||
Reference in New Issue
Block a user