NI: don't filter flexible types during CST calculation and force return as result the first of such types

^KT-35658 Fixed
This commit is contained in:
Victor Petukhov
2019-12-19 19:48:38 +03:00
parent 51424ec598
commit 4309f53e11
10 changed files with 1198 additions and 17 deletions
@@ -580,3 +580,28 @@ object AbstractNullabilityChecker {
return isEqualTypeConstructors(type.typeConstructor(), end)
}
}
object AbstractFlexibilityChecker {
fun TypeSystemCommonSuperTypesContext.hasDifferentFlexibilityAtDepth(types: Collection<KotlinTypeMarker>): Boolean {
if (types.isEmpty()) return false
if (hasDifferentFlexibility(types)) return true
for (i in 0 until types.first().argumentsCount()) {
val typeArgumentForOtherTypes = types.mapNotNull {
if (it.argumentsCount() > i && !it.getArgument(i).isStarProjection()) it.getArgument(i).getType() else null
}
if (hasDifferentFlexibilityAtDepth(typeArgumentForOtherTypes)) return true
}
return false
}
private fun TypeSystemCommonSuperTypesContext.hasDifferentFlexibility(types: Collection<KotlinTypeMarker>): Boolean {
val firstType = types.first()
if (types.all { it === firstType }) return false
return !types.all { it.isFlexible() } && !types.all { !it.isFlexible() }
}
}