Constraint system now may return partial substitutor

This commit is contained in:
Svetlana Isakova
2015-09-04 18:14:25 +03:00
parent fe34d1673e
commit d58a8437d7
2 changed files with 11 additions and 2 deletions
@@ -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
}
@@ -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()