[FIR] Skip redundant INAPPLICABLE_CANDIDATE on call with unresolved callable reference argument
A new resolution diagnostic UnsuccessfulCallableReferenceAtom is introduced that is used in EagerResolveOfCallableReferences. No diagnostic is reported on unresolved calls with this diagnostic because #KT-59856
This commit is contained in:
committed by
Space Team
parent
a55f3c5583
commit
2f3293f99e
+2
-2
@@ -34,13 +34,13 @@ fun main() {
|
||||
<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo3<!>(KotlinClass::baz)
|
||||
|
||||
// Type mismatch
|
||||
<!INAPPLICABLE_CANDIDATE!>foo1<!>(KotlinClass::<!UNRESOLVED_REFERENCE!>bar<!>)
|
||||
foo1(KotlinClass::<!UNRESOLVED_REFERENCE!>bar<!>)
|
||||
foo2(KotlinClass::bar)
|
||||
foo3(KotlinClass::bar)
|
||||
|
||||
foo1(KotlinClass2::bar)
|
||||
// Type mismatch
|
||||
<!INAPPLICABLE_CANDIDATE!>foo2<!>(KotlinClass2::<!UNRESOLVED_REFERENCE!>bar<!>)
|
||||
foo2(KotlinClass2::<!UNRESOLVED_REFERENCE!>bar<!>)
|
||||
foo3(KotlinClass2::bar)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -7,6 +7,6 @@ fun <T> bar(f: (T) -> Unit, e: T) {}
|
||||
fun <T> baz(e: T, f: (T) -> Unit) {}
|
||||
|
||||
fun test(a: A, b: B) {
|
||||
<!INAPPLICABLE_CANDIDATE!>baz<!>(a, ::<!UNRESOLVED_REFERENCE!>fooB<!>)
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>(::<!UNRESOLVED_REFERENCE!>fooB<!>, a)
|
||||
baz(a, ::<!UNRESOLVED_REFERENCE!>fooB<!>)
|
||||
bar(::<!UNRESOLVED_REFERENCE!>fooB<!>, a)
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@ fun <T, R> use(x: (T) -> R): (T) -> R = x
|
||||
fun foo() = use(::bar)
|
||||
fun bar(x: String) = 1
|
||||
|
||||
fun loop1() = <!INAPPLICABLE_CANDIDATE!>use<!>(::<!UNRESOLVED_REFERENCE!>loop2<!>)
|
||||
fun loop1() = use(::<!UNRESOLVED_REFERENCE!>loop2<!>)
|
||||
fun loop2() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>loop1()<!>
|
||||
|
||||
Vendored
+1
-1
@@ -3,5 +3,5 @@ fun <T, R> use(x: (T) -> R): (T) -> R = x
|
||||
fun foo() = use(::bar)
|
||||
fun bar(x: String) = 1
|
||||
|
||||
fun loop1() = <!INAPPLICABLE_CANDIDATE!>use<!>(::<!UNRESOLVED_REFERENCE!>loop2<!>)
|
||||
fun loop1() = use(::<!UNRESOLVED_REFERENCE!>loop2<!>)
|
||||
fun loop2() = loop1()
|
||||
|
||||
+3
@@ -255,6 +255,9 @@ private fun mapInapplicableCandidateError(
|
||||
// And the errors should be reported there
|
||||
is ErrorTypeInArguments -> null
|
||||
|
||||
// see EagerResolveOfCallableReferences
|
||||
is UnsuccessfulCallableReferenceAtom -> null
|
||||
|
||||
is MultipleContextReceiversApplicableForExtensionReceivers ->
|
||||
FirErrors.AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER.createOn(qualifiedAccessSource ?: source)
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
@@ -42,6 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DYNAMIC_EXTENSION_FQ_NAME
|
||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
@@ -514,7 +514,13 @@ internal object EagerResolveOfCallableReferences : CheckerStage() {
|
||||
val (applicability, success) =
|
||||
context.bodyResolveComponents.callResolver.resolveCallableReference(candidate.csBuilder, atom)
|
||||
if (!success) {
|
||||
sink.yieldDiagnostic(InapplicableCandidate)
|
||||
// If the resolution was unsuccessful, we ensure that an error will be reported for the callable reference
|
||||
// during completion by using the `resultingReference` of the postponed atom.
|
||||
// We assert that the `resultingReference` is set to an error reference and the atom is in fact postponed.
|
||||
check(atom.resultingReference is FirErrorReferenceWithCandidate)
|
||||
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) check(atom in candidate.postponedAtoms)
|
||||
|
||||
sink.yieldDiagnostic(UnsuccessfulCallableReferenceAtom)
|
||||
} else when (applicability) {
|
||||
CandidateApplicability.RESOLVED_NEED_PRESERVE_COMPATIBILITY ->
|
||||
sink.reportDiagnostic(LowerPriorityToPreserveCompatibilityDiagnostic)
|
||||
|
||||
+2
@@ -76,6 +76,8 @@ class NameForAmbiguousParameter(
|
||||
|
||||
object InapplicableCandidate : ResolutionDiagnostic(INAPPLICABLE)
|
||||
|
||||
object UnsuccessfulCallableReferenceAtom : ResolutionDiagnostic(INAPPLICABLE)
|
||||
|
||||
object ErrorTypeInArguments : ResolutionDiagnostic(INAPPLICABLE)
|
||||
|
||||
object HiddenCandidate : ResolutionDiagnostic(HIDDEN)
|
||||
|
||||
Reference in New Issue
Block a user