K2: discriminate particular SAMs in the first place in ConeOverloadConflictResolver
Before this commit, we discriminated particular candidates with SAM during resolution stages. More precisely, candidates from Kotlin which used Java SAM types, were discriminated allowing go up the tower for better candidates. After disabling compatibility mode for new inference, it's not so, but now we discriminate similar candidates in ConeOverloadConflictResolver. This does not allow going up the tower, but allows to select better candidate at similar tower level. Related to KT-63558, KT-64306
This commit is contained in:
committed by
Space Team
parent
a7dc381b93
commit
087edc026d
+1
-1
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
abstract class AbstractConeCallConflictResolver(
|
||||
private val specificityComparator: TypeSpecificityComparator,
|
||||
protected val inferenceComponents: InferenceComponents,
|
||||
private val transformerComponents: BodyResolveComponents,
|
||||
protected val transformerComponents: BodyResolveComponents,
|
||||
private val considerMissingArgumentsInSignatures: Boolean,
|
||||
) : ConeCallConflictResolver() {
|
||||
|
||||
|
||||
+5
@@ -163,6 +163,11 @@ class ConeOverloadConflictResolver(
|
||||
discriminateSuspendConversions: Boolean,
|
||||
discriminateByUnwrappedSmartCastOrigin: Boolean,
|
||||
): Set<Candidate> {
|
||||
val withoutLowPrioritySAM = candidates.filterTo(mutableSetOf()) { !it.shouldHaveLowPriorityDueToSAM(transformerComponents) }
|
||||
if (withoutLowPrioritySAM.size == 1) {
|
||||
return withoutLowPrioritySAM
|
||||
}
|
||||
|
||||
findMaximallySpecificCall(candidates, false)?.let { return setOf(it) }
|
||||
|
||||
if (discriminateGenerics) {
|
||||
|
||||
+12
-1
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.matchingParameterFunctionType
|
||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||
import org.jetbrains.kotlin.fir.references.FirThisReference
|
||||
import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.directExpansionType
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.*
|
||||
@@ -512,7 +513,7 @@ internal object CheckArguments : CheckerStage() {
|
||||
}
|
||||
|
||||
// Logic description: only candidates from Kotlin, but using Java SAM types, are discriminated
|
||||
candidate.usesSAM && !candidate.isJavaApplicableCandidate() -> {
|
||||
candidate.shouldHaveLowPriorityDueToSAM(context.bodyResolveComponents) -> {
|
||||
if (argumentMapping.values.any {
|
||||
val coneType = it.returnTypeRef.coneType
|
||||
context.bodyResolveComponents.samResolver.isSamType(coneType) &&
|
||||
@@ -527,6 +528,16 @@ internal object CheckArguments : CheckerStage() {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Candidate.shouldHaveLowPriorityDueToSAM(bodyResolveComponents: BodyResolveComponents): Boolean {
|
||||
if (!usesSAM || isJavaApplicableCandidate()) return false
|
||||
return argumentMapping!!.values.any {
|
||||
val coneType = it.returnTypeRef.coneType
|
||||
bodyResolveComponents.samResolver.isSamType(coneType) &&
|
||||
// Candidate is not from Java, so no flexible types are possible here
|
||||
coneType.toRegularClassSymbol(bodyResolveComponents.session)?.isJavaOrEnhancement == true
|
||||
}
|
||||
}
|
||||
|
||||
private fun Candidate.isJavaApplicableCandidate(): Boolean {
|
||||
val symbol = symbol as? FirFunctionSymbol ?: return false
|
||||
if (symbol.isJavaOrEnhancement) return true
|
||||
|
||||
Reference in New Issue
Block a user