Constraint system now may return partial substitutor
This commit is contained in:
@@ -82,4 +82,9 @@ public interface ConstraintSystem {
|
||||
* If there is no information for type parameter, returns type projection for DONT_CARE type.
|
||||
*/
|
||||
public fun getCurrentSubstitutor(): TypeSubstitutor
|
||||
|
||||
/**
|
||||
* Returns a substitution only for type parameters that have result values, otherwise returns a type parameter itself.
|
||||
*/
|
||||
public fun getPartialSubstitutor(): TypeSubstitutor
|
||||
}
|
||||
|
||||
+6
-2
@@ -108,16 +108,17 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
substituteOriginal: Boolean
|
||||
): Map<TypeParameterDescriptor, TypeProjection> {
|
||||
val substitutionContext = HashMap<TypeParameterDescriptor, TypeProjection>()
|
||||
for ((typeParameter, typeBounds) in typeParameterBounds) {
|
||||
for ((variable, typeBounds) in typeParameterBounds) {
|
||||
val typeProjection: TypeProjection
|
||||
val value = typeBounds.value
|
||||
val typeParameter = if (substituteOriginal) variablesToOriginal[variable]!! else variable
|
||||
if (value != null && !TypeUtils.containsSpecialType(value, DONT_CARE)) {
|
||||
typeProjection = TypeProjectionImpl(value)
|
||||
}
|
||||
else {
|
||||
typeProjection = getDefaultTypeProjection(typeParameter)
|
||||
}
|
||||
substitutionContext.put(if (substituteOriginal) variablesToOriginal[typeParameter]!! else typeParameter, typeProjection)
|
||||
substitutionContext.put(typeParameter, typeProjection)
|
||||
}
|
||||
return substitutionContext
|
||||
}
|
||||
@@ -449,6 +450,9 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
override fun getCurrentSubstitutor() =
|
||||
getSubstitutor(substituteOriginal = true) { TypeProjectionImpl(TypeUtils.DONT_CARE) }
|
||||
|
||||
override fun getPartialSubstitutor() =
|
||||
getSubstitutor(substituteOriginal = true) { TypeProjectionImpl(it.correspondingType) }
|
||||
|
||||
private fun getSubstitutor(substituteOriginal: Boolean, getDefaultValue: (TypeParameterDescriptor) -> TypeProjection) =
|
||||
replaceUninferredBy(getDefaultValue, substituteOriginal).setApproximateCapturedTypes()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user