[FE 1.0] Eliminate resolution ambiguity on inherited SAM-interfaces
^KT-17765 Fixed
This commit is contained in:
committed by
teamcityserver
parent
a5c6d370dd
commit
a6fd14d4e6
+47
-8
@@ -12,18 +12,34 @@ interface SpecificityComparisonCallbacks {
|
||||
fun isNonSubtypeNotLessSpecific(specific: KotlinTypeMarker, general: KotlinTypeMarker): Boolean
|
||||
}
|
||||
|
||||
class TypeWithConversion(val resultType: KotlinTypeMarker?, val originalTypeIfWasConverted: KotlinTypeMarker? = null)
|
||||
|
||||
class FlatSignature<out T> constructor(
|
||||
val origin: T,
|
||||
val typeParameters: Collection<TypeParameterMarker>,
|
||||
val valueParameterTypes: List<KotlinTypeMarker?>,
|
||||
val hasExtensionReceiver: Boolean,
|
||||
val hasVarargs: Boolean,
|
||||
val numDefaults: Int,
|
||||
val isExpect: Boolean,
|
||||
val isSyntheticMember: Boolean
|
||||
val isSyntheticMember: Boolean,
|
||||
val valueParameterTypes: List<TypeWithConversion?>,
|
||||
) {
|
||||
val isGeneric = typeParameters.isNotEmpty()
|
||||
|
||||
constructor(
|
||||
origin: T,
|
||||
typeParameters: Collection<TypeParameterMarker>,
|
||||
valueParameterTypes: List<KotlinTypeMarker?>,
|
||||
hasExtensionReceiver: Boolean,
|
||||
hasVarargs: Boolean,
|
||||
numDefaults: Int,
|
||||
isExpect: Boolean,
|
||||
isSyntheticMember: Boolean,
|
||||
) : this(
|
||||
origin, typeParameters, hasExtensionReceiver, hasVarargs, numDefaults, isExpect,
|
||||
isSyntheticMember, valueParameterTypes.map(::TypeWithConversion)
|
||||
)
|
||||
|
||||
companion object
|
||||
}
|
||||
|
||||
@@ -39,19 +55,18 @@ interface SimpleConstraintSystem {
|
||||
val context: TypeSystemInferenceExtensionContext
|
||||
}
|
||||
|
||||
fun <T> SimpleConstraintSystem.isSignatureNotLessSpecific(
|
||||
private fun <T> SimpleConstraintSystem.isValueParameterTypeNotLessSpecific(
|
||||
specific: FlatSignature<T>,
|
||||
general: FlatSignature<T>,
|
||||
callbacks: SpecificityComparisonCallbacks,
|
||||
specificityComparator: TypeSpecificityComparator
|
||||
specificityComparator: TypeSpecificityComparator,
|
||||
typeKindSelector: (TypeWithConversion?) -> KotlinTypeMarker?
|
||||
): Boolean {
|
||||
if (specific.hasExtensionReceiver != general.hasExtensionReceiver) return false
|
||||
if (specific.valueParameterTypes.size != general.valueParameterTypes.size) return false
|
||||
|
||||
val typeParameters = general.typeParameters
|
||||
val typeSubstitutor = registerTypeVariables(typeParameters)
|
||||
val valueParameterTypes = specific.valueParameterTypes.map(typeKindSelector).zip(general.valueParameterTypes.map(typeKindSelector))
|
||||
|
||||
for ((specificType, generalType) in specific.valueParameterTypes.zip(general.valueParameterTypes)) {
|
||||
for ((specificType, generalType) in valueParameterTypes) {
|
||||
if (specificType == null || generalType == null) continue
|
||||
|
||||
if (specificityComparator.isDefinitelyLessSpecific(specificType, generalType)) {
|
||||
@@ -80,6 +95,30 @@ fun <T> SimpleConstraintSystem.isSignatureNotLessSpecific(
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun <T> SimpleConstraintSystem.isSignatureNotLessSpecific(
|
||||
specific: FlatSignature<T>,
|
||||
general: FlatSignature<T>,
|
||||
callbacks: SpecificityComparisonCallbacks,
|
||||
specificityComparator: TypeSpecificityComparator,
|
||||
useOriginalSamTypes: Boolean = false
|
||||
): Boolean {
|
||||
if (specific.hasExtensionReceiver != general.hasExtensionReceiver) return false
|
||||
if (specific.valueParameterTypes.size != general.valueParameterTypes.size) return false
|
||||
|
||||
if (!isValueParameterTypeNotLessSpecific(specific, general, callbacks, specificityComparator) { it?.resultType }) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (useOriginalSamTypes && !isValueParameterTypeNotLessSpecific(
|
||||
specific, general, callbacks, specificityComparator
|
||||
) { it?.originalTypeIfWasConverted }
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
return !hasContradiction()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user