Checking for conflicting substitutors in completion after "by"

This commit is contained in:
Valentin Kipyatkov
2016-03-31 22:21:29 +03:00
parent e05d6a7056
commit 24764ed865
6 changed files with 55 additions and 8 deletions
@@ -184,3 +184,18 @@ class FuzzyType(
return TypeSubstitutor.create(TypeConstructorSubstitution.createByConstructorsMap(substitution))
}
}
fun TypeSubstitution.hasConflictWith(other: TypeSubstitution, freeParameters: Collection<TypeParameterDescriptor>): Boolean {
return freeParameters.any { parameter ->
val type = parameter.defaultType
val substituted1 = this[type] ?: return@any false
val substituted2 = other[type] ?: return@any false
!KotlinTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(substituted1.type, substituted2.type) || substituted1.projectionKind != substituted2.projectionKind
}
}
fun TypeSubstitutor.combineIfNoConflicts(other: TypeSubstitutor, freeParameters: Collection<TypeParameterDescriptor>): TypeSubstitutor? {
if (this.substitution.hasConflictWith(other.substitution, freeParameters)) return null
return TypeSubstitutor.createChainedSubstitutor(this.substitution, other.substitution)
}